Home  >  Article  >  Backend Development  >  PHP array sum operation

PHP array sum operation

不言
不言Original
2018-04-26 09:42:521684browse

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=[
&#39;1&#39;=>[
   	2,3,4,5,6
],
&#39;2&#39;=>[
        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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn