PHP array_product() function with example

PHP array_product() function with example

array_product() work is utilized to discover the product everything being equal (estimations) of an array, this technique acknowledges an array and returns the product all things considered.

Note: If any component is contained in the array, it returns 0.

Syntax:

 array_product(array);

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

Recent Posts

error: Alert: Content is protected!!