PHP computes the sum and product of values in an array (Array_sum and array_product functions), sumproduct_php Tutorial

Source: Internet
Author: User
Tags getting started with php

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

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