PHP calculates the sum and product of the values in the array (array_sum and array_product functions), sumproduct_PHP tutorial

Source: Internet
Author: User
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?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.