array_reduce

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

Example

<?php
function reduce($arg1, $arg2){
$arg1 += $arg2;
return $arg1;
}

$array1 = array(1, 7, 8, 4, 5);
$array2 = array_reduce($array1, “reduce”);
print_r($array2);
?>

Output

25

Share