Array_sum () of the php array function sequence-calculates the sum of array element values. Array_sum () defines and uses the array_sum () function to return the sum of all values in the array. If all values are integers, an integer is returned. If one or more of these values are floating point numbers
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
The code is as follows:
$ A = array (0 => "5", 1 => "15", 2 => "25 ");
Echo array_sum ($ );
?>
Output:
45
Example 2
The code is as follows:
$ A = array (0 => 5, 1 => 15, 2 => 25 );
Echo array_sum ($ );
?>
Output:
45
Example 3
The code is as follows:
$ A = array (0 => 5, 1 => 15.5, 2 => 25 );
Echo array_sum ($ );
?>
Output:
45.5
Example 4
The code is as follows:
$ A = array (0 => 5, 1 => "15 s", 2 => 25 );
Echo array_sum ($ );
?>
Output:
45
Example 5
The code is as follows:
$ A = array (0 => 5, 1 => "s15s", 2 => 25 );
Echo array_sum ($ );
?>
Output:
30
The http://www.bkjia.com/PHPjc/324490.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/324490.htmlTechArticlearray_sum () definition and usage 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 is floating point...