PHPize Online / SQLize Online

Popular

array_reduce

Tags: PHP 5.x PHP 7.x PHP 8.x

array_reduce — Iteratively reduce the array to a single value using a callback function.

Description

array_reduce(
    array $array,
callable $callback,
mixed $initial = null
): mixed
array_reduce() applies iteratively the callback function to the elements of the array, so as to reduce the array to a single value.

Parameters

array
The input array.
callback
callback(
    mixed $carry, 
    mixed $item
): mixed
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 Values

Returns the new number of elements in the array.