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

Discuss this tutorial at forum


Further readings
 PHP array
array : Creating an Array
array_diff Difference of two arrays
array_count_values counting the frequency of values inside an array
count : sizeof Array Size or length
array_push : Adding element to an Array
array_sum : Array Sum of all elements
Displaying the elements of an array
Array checkbox
in_array : IN Array to search for elements inside an array
array_rand : Random elements of Array
array_unique : Array Unique values
Breaking of strings to create array using split command
unset : Deleting elements of an array by using its key
sort: Simple sorting of PHP array
rsort: Reverse sorting of PHP array
asort: Maintaining index of the elements after sorting
arsort: Sorting in reverse order for a PHP array
ksort: Array key Sorting in PHP
krsort: Array reverse key Sorting in PHP
usort: Sorting array by using user defined function























 

Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.

Scripts
PHP
JavaScript
PHP Tutorials
Array Functions
PHP Sections
PHP Introduction
Loops & structure
Array
Date & Time
Functions
Form Handling
File Handling
Math Functions
String Functions
GD Functions
Comment Posting
Content Management
PHP & Ajax
Popular Tutorials
Drop down list
File Upload
Signup script
Member Login
Line Graph
PHP MySQL Paging
PHP Calendar
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.