September 2001
Intermediate to advanced
768 pages
32h 45m
English
mixed array_sum(array array) Returns the sum of an array’s elements.
Returns:
Sum of the values in an array; NULL on failure
Description:
This function simply totals the numeric values of the elements of array and returns the result. If array contains other arrays or objects, they’re skipped. Non-numeric values in array are internally cast to their numeric equivalents for the addition; this casting is internal only and these values still have their original values and types after the call.
Version:
PHP 4 since 4.0.4
Example:
$array = array(1, 2, "3.3 kilograms", array(4));
echo "The sum of the elements is: " . array_sum($array) . "\n";
Output:
The sum of the elements is: 6.3
|
Read now
Unlock full access