From http://www.w3schools.com (Copyright Refsnes Data)
The array_reduce() function sends the values in an array to a user-defined function, and returns a string.
array_reduce(array,function,initial) |
Parameter | Description |
---|---|
array | Required. Specifies an array |
function | Required. Specifies the name of the function |
initial | Optional. Specifies the initial value to send to the function |
<?php function myfunction($v1,$v2) { return $v1 . "-" . $v2; } $a=array("Dog","Cat","Horse"); print_r(array_reduce($a,"myfunction")); ?> |
The output of the code above will be:
-Dog-Cat-Horse |
With the initial parameter:
<?php function myfunction($v1,$v2) { return $v1 . "-" . $v2; } $a=array("Dog","Cat","Horse"); print_r(array_reduce($a,"myfunction",5)); ?> |
The output of the code above will be:
5-Dog-Cat-Horse |
Returning a sum:
<?php function myfunction($v1,$v2) { return $v1+$v2; } $a=array(10,15,20); print_r(array_reduce($a,"myfunction",5)); ?> |
The output of the code above will be:
50 |
From http://www.w3schools.com (Copyright Refsnes Data)