array_sum() definition and usage
array_sum() function returns the sum of all values in the array.
If all values are integers, return an integer value. If one or more of the values is a floating point number, a floating point number is returned.
Pre-PHP 4.2.1 versions modified the passed array itself, converting its string values into numeric values (in most cases converted to zeros, depending on the system).
Syntax
array_sum(array)
Parameter Description
array Required. Specifies the input array.
Example 1
Copy the code The code is as follows:
$a=array(0=>"5",1=>"15",2=>"25" );
echo array_sum($a);
?> >5,1=>15,2=>25);
echo array_sum($a);
Example 3 Copy the code
The code is as follows:
$a=array(0=>5,1=>15.5,2=>25);
echo array_sum($a);
Example 4 Copy the code
The code is as follows:
$a=array(0=>5,1=>"15s",2=>25);
echo array_sum($a);
Example 5 Copy code
The code is as follows:
$a=array(0=>5 ,1=>"s15s",2=>25);
echo array_sum($a);
The above has introduced the PHP array function sequence array_sum - calculating the sum of the array element values, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.