PHP computes the sum and product of values in an array (Array_sum and array_product functions), sumproduct
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.
Articles you may be interested in:
- PHP Array function array_multisort () Usage Example analysis
- PHP Math function Summary (classic worth collecting)
- An explanation of PHP anonymous functions and precautions
- Summary of common array function usage in PHP
- PHP anonymous function and use clause usage instance
- Simply talk about the strlen function in PHP
- Analysis of source code of Array_keys and Array_unique functions in PHP
- Php method for querying and deleting multiple columns of data in a database (using array functions)
- PHP Powerful Time-conversion function strtotime
- PHP function Timeout processing method
- Probe into the anonymous function of PHP's closure (Closure)
- php function Import_request_variables () usage analysis
http://www.bkjia.com/PHPjc/1117045.html www.bkjia.com true http://www.bkjia.com/PHPjc/1117045.html techarticle PHP computes the sum and product of the values in the array (Array_sum and array_product functions), sumproduct the method of calculating the sum and product of the values in an array of PHP. Share for the big ...