Array_sum () Definition and usage
The array_sum () function returns the sum of all values in the array.
If all values are integers, an integer is returned. If one or more of the values are floating-point numbers, the return value is floating-point numbers.
In versions earlier than PHP 4.2.1, the input array itself is modified to convert the string value to a value (in most cases, it is converted to zero, depending on the specific system ).
Syntax
Array_sum (array)
Parameter description
Array is required. Specifies the input array.
Example 1
Copy codeThe Code is as follows:
<? Php
$ A = array (0 => "5", 1 => "15", 2 => "25 ");
Echo array_sum ($ );
?>
Output:
45
Example 2
Copy codeThe Code is as follows:
<? Php
$ A = array (0 => 5, 1 => 15, 2 => 25 );
Echo array_sum ($ );
?>
Output:
45
Example 3
Copy codeThe Code is as follows:
<? Php
$ A = array (0 => 5, 1 => 15.5, 2 => 25 );
Echo array_sum ($ );
?>
Output:
45.5
Example 4
Copy codeThe Code is as follows:
<? Php
$ A = array (0 => 5, 1 => "15 s", 2 => 25 );
Echo array_sum ($ );
?>
Output:
45
Example 5
Copy codeThe Code is as follows:
<? Php
$ A = array (0 => 5, 1 => "s15s", 2 => 25 );
Echo array_sum ($ );
?>
Output:
30