php多维数组循环相加问题,如下 大神们
$arr=array(array('id'=>7363,'fd'=>1,'fb'=>1,'tcp'=>0,'fbdh'=>1,'jxs'=>'GZYX'),array('...
$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 展开
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 展开
展开全部
不知道你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;
$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;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
$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<count($arr);$i++){
$test['fd']+=$arr[$i]['fd'];
$test['fb']+=$arr[$i]['fb'];
$test['tcp']+=$arr[$i]['tcp'];
$test['fbdh']+=$arr[$i]['fbdh'];
}
print_r($test);
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询