Home > Article > Backend Development > PHP array sum operation
This article introduces the content of PHP array sum operation, which has certain reference value. Now I share it with everyone. Friends in need can refer to it
<?php /*二维数组的加和计算 $arr=[ '1'=>[ 2,3,4,5,6 ], '2'=>[ 7,8,9,10 ] ]; var_dump($arr[1][0]); $num=count($arr[1]); $sum=0; for($ii=0; $ii<$num; $ii++) { $sum=$sum+$arr[1][$ii]; } var_dump($sum); */ /*一维数组的加和计算 $arr=[1,2,3,4,5,6,7,8,9,10]; $num=count($arr); $sum=0; for($ii=0; $ii<$num; $ii++) { $sum+=$arr[$ii]; } var_dump($sum); */ ?>
Related recommendations:
Functions for converting PHP arrays to XML
The above is the detailed content of PHP array sum operation. For more information, please follow other related articles on the PHP Chinese website!