PHP array function sequence array_sum - calculates the sum of array element values

WBOY
Release: 2016-07-29 08:47:03
Original
1412 people have browsed it

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);

?>


Output:
45

Example 3 Copy the 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 the 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

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.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template