Home > php教程 > php手册 > body text

php 数组值求和之array_sum()函数

WBOY
Release: 2016-06-13 10:03:46
Original
2554 people have browsed it

本教程人简单的讲述一下关于php的中的统计数组中数字型数据的和函数array_sum()的用法。

例子1
 代码如下:

 代码如下 复制代码

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

输出:

45

例子2
 代码如下:

 代码如下 复制代码

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

输出:

45

例子3
 代码如下:

 代码如下 复制代码

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

输出:

45.5

例子4
 代码如下:

 代码如下 复制代码

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

输出:

45

例子5
 代码如下:

 代码如下 复制代码

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

输出:

30

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!