SQL PHP HTML ASP JavaScript articles and free scripts to download
 

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.3

The output of the above line would be 9.3 ( the sum of all values inside the array)

You can find out number of element present inside an array by using sizeoff() function.







Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked


Join Our Email List
Email:  
For Email Newsletters you can trust
Array Functions
PHP Sections