Menu Samaritan's Purse

ARRAY_REDUCE

Iteratively reduce the array to a single value using a callback function

SYNTAX

array_reduce ( array $array , callable $callback [, mixed $initial = NULL ] ) : mixed

PARAMETERS

array

The input array.

callback ( mixed $carry , mixed $item ) : mixed

CARRY

Holds the return value of the previous iteration; in the case of the first iteration it instead holds the value of initial.

ITEM

Holds the value of the current iteration.

initial

If the optional initial is available, it will be used at the beginning of the process, or as a final result in case the array is empty.

RETURN

Returns the resulting value.

EXAMPLES

ARRAY CALLBACK

10

INITIAL | NULL

10

INITIAL | NOT NULL

15

INITIAL | EMPTY ARRAY

empty

PHP