This tutorial briefly talks about the usage of the sum function array_sum() of numeric data in statistical arrays in PHP.
Example 1
The code is as follows:
The code is as follows
|
Copy code
|
||||
代码如下 | 复制代码 | ||||
$a=array(0=>5,1=>15,2=>25); 输出: 45 |
echo array_sum($a);
?>
代码如下 | 复制代码 |
$a=array(0=>5,1=>15.5,2=>25); 输出: 45.5 |
45
代码如下 | 复制代码 |
$a=array(0=>5,1=>"15s",2=>25); 输出: 45 |
代码如下 | 复制代码 |
$a=array(0=>5,1=>"s15s",2=>25); 输出: 30 |
The code is as follows | Copy code |
$a=array(0=>5,1=>15,2=>25); echo array_sum($a); ?> Output: 45 Example 3 The code is as follows:
The code is as follows | Copy code
$a=array(0=>5,1=>15.5,2=>25);
echo array_sum($a);
?>
Output:
45.5
Example 4
The code is as follows:
|
|