The example in this article describes how PHP calculates the sum and product of values in an array. Share it with everyone for your reference, the details are as follows:
1. Overview:
array_sum() function is used to calculate the sum of all values in an array.
The array_product() function is used to calculate the product of all values in an array.
2. Usage examples:
array_sum()
PHP array_sum() function is used to calculate the sum of all values in the array, and returns the calculation result as an integer or floating point number. Non-numeric units will be treated as 0.
Syntax:
1 |
|
Example:
1 2 3 4 |
|
array_product()
PHP array_product() function is used to calculate the product of all values in the array, and returns the calculation result as an integer or floating point number. Non-numeric units will be treated as 0.
Syntax:
1 |
|
Example:
1 2 3 4 5 6 |
|
Readers who are interested in more PHP-related content can check out the special topics on this site: "Summary of PHP operations and operator usage", "Summary of PHP network programming skills", " Introductory tutorial on PHP basic syntax", "Summary of PHP office document operation skills (including word, excel, access, ppt)", "Summary of PHP date and time usage》, "php object-oriented programming introductory tutorial", "php string (string) usage summary", "php mysql database operation introductory tutorial" And "Summary of common database operation skills in PHP"
I hope this article will be helpful to everyone in PHP programming.