In this paper, we present a method for calculating the sum and product of values in an array of PHP. Share to everyone for your reference, as follows:
First, overview:
The Array_sum () function is used to calculate the and of all values in the array.
The Array_product () function calculates the product of all the values in the array.
Second, use example:
Array_sum ()
The PHP array_sum () function calculates the value of all the values in the array and returns the calculated result as an integer or floating-point number, and the non-numeric unit 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 the array, returns the result of the calculation as an integer or floating-point number, and the non-numeric unit 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 readers interested in PHP related content can view this site: "Summary of PHP operations and operator usage," PHP Network Programming Tips Summary, "PHP Basic Grammar Primer Tutorial", "PHP operation Office Document tips summary (including word,excel,access, ppt), "PHP Date and Time usage summary", "PHP primer for Object-oriented programming", "PHP String Usage Summary", "Getting Started with Php+mysql database operations" and "PHP Common Database Operations Skills Summary"
I hope this article is helpful to you in PHP programming.
The above describes the PHP calculation of the value of the sum and the product of the method Array_sum and Array_product function, including the product,array aspect of the content, I hope to be interested in PHP tutorial friends helpful.