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

How to use php array_sum function

藏色散人
Release: 2023-02-22 18:22:01
Original
3614 people have browsed it

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)
Copy after login

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

$a=array("Lipstick"=>199," Foundation"=>349,"Eyeshadow"=>99);

echo array_sum($a);

?>

Output:

647
Copy after login

php array_sum() function usage example 2

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

Output:

那么你这个月要还4078
Copy after login

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!

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