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 the string values in it to numeric values (or zeros in most cases, depending on the system).
Syntax
array_sum(array)
Parameter Description
array Required. Specifies the input array.
Example 1
Copy code The code is as follows:
$a= array(0=>"5",1=>"15",2=>"25");
echo array_sum($a);
?>
Output:
45
Example 2
Copy code The code is as follows:
< ?php
$a=array(0=>5,1=>15,2=>25);
echo array_sum($a);
?>
Output:
45
Example 3
Copy code The code is as follows:
$a=array(0=>5,1=>15.5,2=>25);
echo array_sum($a);
?>
Output:
45.5
Example 4
Copy code The code is as follows:
$a=array(0=>5,1=>"15s",2=>25);
echo array_sum($a);
?> ;
Output:
45
Example 5
Copy code The code is as follows:
$a=array(0=>5,1=>"s15s",2=>25);
echo array_sum($a);
?>
Output:
30
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 value is returned. If one or more of the values is a floating point number...
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn