$arr = array(
array('id'=>7363,'fd'=>1,'fb'=>1,'tcp'=>0,'fbdh'=>1,'jxs'=>'GZYX'),
array('id'=>7412,'fd'=>1,'fb'=>0,'tcp'=>1,'fbdh'=>1,'jxs'=>'GZYX'),
array('id'=>7512,'fd'=>1,'fb'=>1,'tcp'=>0,'fbdh'=>1,'jxs'=>'GZYX'),
);
如何把上面数组变成下面的结果
结果:GZYX 3 2 1 3
php多维数组循环相加问题,如下 大神们
答案:2 悬赏:30 手机版
解决时间 2021-03-13 22:46
- 提问者网友:雾里闻花香
- 2021-03-13 14:05
最佳答案
- 五星知识达人网友:轻雾山林
- 2021-03-13 14:57
$arr = array(
array('id'=>7363,'fd'=>1,'fb'=>1,'tcp'=>0,'fbdh'=>1,'jxs'=>'GZYX'),
array('id'=>7412,'fd'=>1,'fb'=>0,'tcp'=>1,'fbdh'=>1,'jxs'=>'GZYX'),
array('id'=>7512,'fd'=>1,'fb'=>1,'tcp'=>0,'fbdh'=>1,'jxs'=>'GZYX'),
);
$test=array('fd'=>0,'fb'=>0,'tcp'=>0,'fbdh'=>0,'jxs'=>'');
$test['jxs']='GZYX';
for($i=0;$i
$test['fd']+=$arr[$i]['fd'];
$test['fb']+=$arr[$i]['fb'];
$test['tcp']+=$arr[$i]['tcp'];
$test['fbdh']+=$arr[$i]['fbdh'];
}
print_r($test);
array('id'=>7363,'fd'=>1,'fb'=>1,'tcp'=>0,'fbdh'=>1,'jxs'=>'GZYX'),
array('id'=>7412,'fd'=>1,'fb'=>0,'tcp'=>1,'fbdh'=>1,'jxs'=>'GZYX'),
array('id'=>7512,'fd'=>1,'fb'=>1,'tcp'=>0,'fbdh'=>1,'jxs'=>'GZYX'),
);
$test=array('fd'=>0,'fb'=>0,'tcp'=>0,'fbdh'=>0,'jxs'=>'');
$test['jxs']='GZYX';
for($i=0;$i
$test['fb']+=$arr[$i]['fb'];
$test['tcp']+=$arr[$i]['tcp'];
$test['fbdh']+=$arr[$i]['fbdh'];
}
print_r($test);
全部回答
- 1楼网友:一袍清酒付
- 2021-03-13 15:27
不知道你jxs的逻辑是上面情况,你可以自己添加代码
$arr = array(array('id'=>7363,'fd'=>1,'fb'=>1,'tcp'=>0,'fbdh'=>1,'jxs'=>'GZYX'),array('id'=>7412,'fd'=>1,'fb'=>0,'tcp'=>1,'fbdh'=>1,'jxs'=>'GZYX'),array('id'=>7512,'fd'=>1,'fb'=>1,'tcp'=>0,'fbdh'=>1,'jxs'=>'GZYX'),);$fd=null;$fb=null;$tcp=null;$fbdh=null;$jxs=null;foreach($arr as $r){$fd+=$r['fd'];$fb+=$r['fb'];$tcp+=$r['tcp'];$fbdh+=$r['fbdh'];//$jxs的逻辑根据你的情况添加}echo $jxs. ' '.$fd. ' '.$fb. ' '.$tcp. ' '.$fbdh;
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯