這是二維數組,我想去到total的集合,並計算total的總值,請問怎麼實現
array( [0] => Array ( [id] => 5 [title] => 相宜本草八倍凝水霜50g 保濕補水滋潤美白面霜乳液男女正品護膚品 [images] => uploadfile/goods/2015-01/1420774763.jpg [price] => 39.0 [num] => 1 [total] => 39 [wlmoney] => 0 [url] => http://localhost/dkyq/goods.php?id=12 ) [1] => Array ( [id] => 4 [title] => 美膚寶正品 水份源潔面膏潔面乳75ml 洗面奶清潔爽膚 補水保濕 [images] => uploadfile/goods/2015-01/1420773795.jpg [price] => 12.0 [num] => 1 [total] => 12 [wlmoney] => 0 [url] => http://localhost/dkyq/goods.php?id=11 ) );
回複討論(解決方案)
$ar = array ( 0 => array ( 'id' => '5', 'title' => '相宜本草八倍凝水霜50g 保濕補水滋潤美白面霜乳液男女正品護膚品', 'images' => 'uploadfile/goods/2015-01/1420774763.jpg', 'price' => '39.0', 'num' => '1', 'total' => '39', 'wlmoney' => '0', 'url' => 'http://localhost/dkyq/goods.php?id=12', ), 1 => array ( 'id' => '4', 'title' => '美膚寶正品 水份源潔面膏潔面乳75ml 洗面奶清潔爽膚 補水保濕', 'images' => 'uploadfile/goods/2015-01/1420773795.jpg', 'price' => '12.0', 'num' => '1', 'total' => '12', 'wlmoney' => '0', 'url' => 'http://localhost/dkyq/goods.php?id=11', ),);$total = 0;foreach($ar as $r) $total += $r['total'];echo $total; //51
$arr = array( array( 'id' => '5', 'title' => '相宜本草八倍凝水霜50g 保濕補水滋潤美白面霜乳液男女正品護膚品', 'images' => 'uploadfile/goods/2015-01/1420774763.jpg', 'price' => '39.0', 'num' => '1', 'total' => '39', 'wlmoney' => '0', 'url' => 'http://localhost/dkyq/goods.php?id=12', ), array( 'id' => '4', 'title' => '美膚寶正品 水份源潔面膏潔面乳75ml 洗面奶清潔爽膚 補水保濕', 'images' => 'uploadfile/goods/2015-01/1420773795.jpg', 'price' => '12.0', 'num' => '1', 'total' => '12', 'wlmoney' => '0', 'url' => 'http://localhost/dkyq/goods.php?id=11', ));$total = 0;foreach($arr as $v){ $total += $v['total'];}echo $total;
total = 51
不好意思了,因為版主回答的比較早,後面我只能少給點了,希望不要介意呀