Home  >  Article  >  Backend Development  >  PHP array_sum() function for summing array values_PHP tutorial

PHP array_sum() function for summing array values_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 16:59:362082browse

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
 代码如下 复制代码

$a=array(0=>"5",1=>"15",2=>"25");
echo array_sum($a);
?>

输出:

45

Copy code


 代码如下 复制代码

$a=array(0=>5,1=>15,2=>25);
echo array_sum($a);
?>

输出:

45

$a=array(0=>"5",1=>"15",2=>"25");

echo array_sum($a);
?>

 代码如下 复制代码

$a=array(0=>5,1=>15.5,2=>25);
echo array_sum($a);
?>

输出:

45.5

Output:


45

 代码如下 复制代码

$a=array(0=>5,1=>"15s",2=>25);
echo array_sum($a);
?>

输出:

45


Example 2
 代码如下 复制代码

$a=array(0=>5,1=>"s15s",2=>25);
echo array_sum($a);
?>

输出:

30

The code is as follows:
The code is as follows
Copy code

$a=array(0=>5,1=>15,2=>25); ?> 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:
The code is as follows Copy code
$a=array(0=>5,1=>"15s",2=>25); echo array_sum($a); ?> Output: 45 Example 5 The code is as follows:
The code is as follows Copy code
$a=array(0=>5,1=>"s15s",2=>25); echo array_sum($a); ?> Output: 30 http://www.bkjia.com/PHPjc/631313.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631313.htmlTechArticleThis tutorial briefly talks about the sum function array_sum() of numeric data in statistical arrays in PHP usage. Example 1 The code is as follows: The code is as follows Copy the code ?php $a=array(0=...
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