PHP | array_product() Function Last Updated : 31 Aug, 2020 Comments Improve Suggest changes Like Article Like Report The array_product() is an inbuilt function in PHP and it returns the product of all numbers present in the given array. The function accepts an array which consists of numbers only. If the array has any other data except numbers, the function returns 0. Syntax: array_product($array) Parameters: The function has one mandatory parameter $array, for which we want to calculate the product of all values. Return Value: This function returns three different values based on the below cases: It returns 0 if the array consists of atleast one non-number data. It returns 1 when an empty array is passed as a parameter. If both of the above two cases are not met then it returns the product of all the terms in array. Examples: Input : $array = [1, 2, 3, 4] Output : 24 Input : $array = [1, 'a'] Output : 0 Below programs illustrate the array_product() function: Program 1: Program to demonstrate the array_product() function. php <?php // PHP program to demonstrate // the array_product() function $a1=array(1, 2, 3, 4); echo(array_product($a1)); ?> Output: 24 Program 2: Program to demonstrate the array_product() function when the array contains at least one non-number data. php <?php // PHP program to demonstrate the array_product() // function when the array contains at least // one non-number data $a1=array(1, 2, 3, 'a'); echo(array_product($a1)); ?> Output: 0 Program 3: Program to demonstrate the array_product() function when the array is empty. php <?php // PHP program to demonstrate the array_product() function // when the array is empty $a1=array(); echo(array_product($a1)); ?> Output: 1 Reference: http://php.net/manual/en/function.array-product.php Comment More infoAdvertise with us Next Article PHP | array_product() Function S Striver Follow Improve Article Tags : Misc Web Technologies PHP PHP-array Practice Tags : Misc Similar Reads PHP array_product() Function There are some point of time when we need to calculate the product of all elements in an array. The most basic way to do this is to iterate over all elements and calculate the product but PHP serves us with a builtin function to do this. The array_product() is a built-in function in PHP and is used 2 min read PHP array_reduce() Function This inbuilt function of PHP is used to reduce the elements of an array into a single value that can be of float, integer or string value. The function uses a user-defined callback function to reduce the input array. Syntax: array_reduce($array, own_function, $initial) Parameters: The function takes 2 min read PHP array_pop() Function This inbuilt function of PHP is used to delete or pop out and return the last element from an array passed to it as parameter. It reduces the size of the array by one since the last element is removed from the array. Syntax: array_pop($array) Parameters: The function takes only one parameter $array, 2 min read PHP array_push() Function This inbuilt function of PHP is used to push new elements into an array. We can push one or more than one element into the array and these elements gets inserted to the end of the array and because of the pushed elements into the array, the length of the array also gets incremented by the number of 3 min read PHP array() Function The array() function is an inbuilt function in PHP which is used to create an array. There are three types of array in PHP: Indexed array: The array which contains numeric index. Syntax: array( val1, val2, val3, ... ) Associative array: The array which contains name as keys. Syntax: array( key=>v 2 min read Like