PHP array_reduce() Function

PHP array_reduce Function


The array_reduce() function sends the values in an array to a user-defined function, and returns a string.

Note: If the array is empty and initial is not passed, this function returns NULL.

Syntax:

The basic syntax of the array_reduce() function is given with:

       array_reduce(arraymyfunctioninitial);

Parameters:
Parameter Description
array Required. Specifies an array
myfunction Required. Specifies the name of the function
initial Optional. Specifies the initial value to send to the function

Example1 : Send the values in an array to a user-defined function and return a string:

Output :  -Web-Designing-House

 

Example 2:  following example with initial parameter

Output : 5-Dog-Cat-Horse