PHP computes the sum and product of values in an array array_sum and ARRAY_PRODUCT functions array product company NumPy array product ARRA

Source: Internet
Author: User
Tags getting started with php php programming
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.

  • 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.