Home » PHP

PHP array_product() function with example

PHP array_product() function: Here, we are going to learn about the array_product() function with example in PHP.
Submitted by IncludeHelp, on February 22, 2019

PHP array_product() function

array_product() function is used to find the product of all elements (values) of an array, this method accepts an array and returns the product of all values.

Note: If any element is text in the array, it returns 0.

Syntax:

    array_product(array);

It accepts an array and returns the product of all values.

Examples:

    Input:
    $arr = array(10, 20, 30, 40, 50);

    Output:
    12000000

PHP code 1: Finding product of all numeric values of an array

<?php
    $arr = array(10, 20, 30, 40, 50);
    //calculating product of all values
    $result = array_product($arr);
    //printing the result
    print_r ($result);
?>

Output

12000000

PHP code 2: Finding product of all values (numeric and text) of an array – it returns 0

<?php
    $arr = array(10, 20, "Hello", 30, 40);
    //calculating product of all values
    $result = array_product($arr);
    //printing the result
    print_r ($result);
?>

Output

0





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.