PHP array_reduce() Function
This function applies iteratively the function function to the elements of the array, so as to reduce the array to a single value.
Note: If the array is empty and initial is not passed, this function returns NULL.
Returns the resulting value
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 |
Syntax
array_reduce(array,myfunction,initial)
Example
function myfunction($s1,$s2)
{
return $s1+$s2;
}
$array=array(20,10,15);
print_r(array_reduce($array,"myfunction",5));
Output
50
Leave a Reply