|
|
|
PHP array Sum or adding elements |
We can store values in an array and calculate the sum of
the values inside the array by using the array_sum function. This function will
add all the values of the array. We will create an array with some integer value
and then find out the sum.
$value= array(2,5,6,8,9);
echo "Sum of vlues = ".array_sum($value)."<br>";
We can store float value in an array and get the sum of
them by using the array_sum command. Here is one example.
$value2= array(1.5,2.3,5.5);
echo "Sum of values = ".array_sum($value2); // Output =9.2
The output of the above line would be 9.2 ( the sum of all values inside the array)
You can find out number of element present inside an array by using sizeoff() function.
| |
| Subscribe |
|
Submit your email address and receive
article and product notifications. Your email is safe with us.
|
|
|
|
|
|