Home >Backend Development >PHP Problem >How to use php array_sum function

How to use php array_sum function

藏色散人
藏色散人Original
2019-05-25 09:55:503590browse

php array_sum function is used to calculate the sum of all values ​​in the returned array. Its syntax is array_sum(arra). The parameter array is required and refers to the specified array.

How to use php array_sum function

#php array_sum function how to use?

Function: Returns the sum of all values ​​in the array.

Syntax:

array_sum(arra)

Parameters:

array Required. Specifies an array.

Description:

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.

php array_sum() function usage example 1

d1dc34bb876fd024bf845d1c60b42b79199," Foundation"=>349,"Eyeshadow"=>99);

echo array_sum($a);

?>

Output:

647

php array_sum() function usage example 2

<?php
$arr = array(&#39;蚂蚁花呗要还&#39; => 578,&#39;蚂蚁借呗要还&#39; => 1500, &#39;网上银行要还&#39; => 2000);
echo "那么你这个月要还".array_sum($arr);
?>

Output:

那么你这个月要还4078

The above is the detailed content of How to use php array_sum function. For more information, please follow other related articles on the PHP Chinese website!

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