This article illustrates the method of calculating the sum and product of the values in a PHP array. Share to everyone for your reference, specific as follows:
First, overview:
The Array_sum () function computes the and of all the values in the array.
The Array_product () function is used to compute the product of all the values in an array.
Second, the use of examples:
Array_sum ()
The PHP array_sum () function computes the and of all the values in the array, returning the result as an integer or floating-point number, and the Non-numeric cell is treated as 0.
Grammar:
Number Array_sum (array array)
Example:
<?php
$arr _a = Array (1, 2, 3, "a");
Echo array_sum ($arr _a); Output: 6
?>
Array_product ()
The PHP array_product () function calculates the product of all the values in an array, returns the result as an integer or floating-point number, and the Non-numeric cell is treated as 0.
Grammar:
Number array_product (array array)
Example:
<?php
$arr _a = Array (1, 2, 3);
Echo array_product ($arr _a); Output: 6
$arr _b = Array (1, 2, 3, "abc");
Echo array_product ($arr _b); Output: 0
?>
More interested in PHP related content readers can view the site topics: "PHP Operations and Operator Usage Summary", "PHP Network Programming Skills Summary", "PHP Basic Grammar Introductory Tutorial", "PHP operation Office Document Skills Summary (including word,excel,access, PPT), "The PHP date and time usage summary", "PHP object-oriented Programming Introduction Course", "PHP string (String) Usage Summary", "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation skill Summary"
I hope this article will help you with the PHP program design.