PHP array sum operation

不言
Release: 2023-03-24 20:00:02
Original
1651 people have browsed it

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);
*/
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!