PHP calculates the sum and product of the values in the array (array_sum and array_product functions) and sumproduct. PHP calculates the sum and product of the values in an array (the array_sum and array_product functions). This example describes how PHP calculates the sum and product of the values in an array. We will share with you how to calculate the sum and product of the values in the array (array_sum and array_product functions) and sumproduct for PHP.
This example describes how PHP calculates the sum and product of the values in an array. We will share this with you for your reference. The details are as follows:
I. Overview:
The array_sum () function is used to calculate the sum of all values in the array.
The array_product () function is used to calculate the product of all values in the array.
II. example:
Array_sum ()
The PHP array_sum () function is used to calculate the sum of all values in the array. the calculation result is returned using an integer or floating point number. a non-digit unit is treated as 0.
Syntax:
Number array_sum (array)
Example:
<? Php $ arr_a = array (1, 2, 3, "a"); echo array_sum ($ arr_a); // output: 6?>
Array_product ()
The PHP array_product () function is used to calculate the product of all values in the array. the calculation result is returned using an integer or floating point number. the unit of a non-number is treated as 0.
Syntax:
Number array_product (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?>