PHP array_reduce() Function

Facebooktwitterredditpinterestlinkedinmailby feather

PHP array_reduce() Function

The array_reduce() function in PHP reduces the array to a single value using by applying a callback function to the elements of the array.

Syntax

Parameter

array(required)– This parameter represents the input array.

callback (required)– This parameter signifies user defined function that is used to hold the value of the $array.

initial(optional)– This parameter represents the value to be sent to the function.

Return

This function returns the resulting reduced value. It can be of any type int, float or string. It returns null if the array is empty and the “initial” parameter is not passed.

Example 1

Output

Example 2

Output

Example 3

Output

Facebooktwitterredditpinterestlinkedinmailby feather