PHP如何2维数组循环时把某个key的值相加

Array ([0] => Array( [id] => 5 [price] => 100 )
[1] => Array( [id] => 6 [price] => 200 )
)
如果后面还有很多,怎么用循环把price相加得到一个总价。

第1个回答  推荐于2016-03-22
<?php
$count = 0;
$price = array(array("id"=>5,"price"=>100),array("id"=>6,"price"=>200));
foreach($price as $key=>$value){
$count += $value["price"];
}
echo $count;
?>本回答被提问者采纳
第2个回答  2009-10-17
我继续观望!

参考资料:?18811300

相似回答