Reducing Arrays in PHP


Use array reduction to combine array elements into a single value, such as summing numbers.

Source Code

$sum = array_reduce($numbers, function($carry, $item) {
    return $carry + $item;
}, 0);
echo $sum;
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments