Utilize array_reduce() to aggregate array data, such as summing numbers.
Source Code
$numbers = [1, 2, 3, 4, 5];
$sum = array_reduce($numbers, function($carry, $item) { return $carry + $item; }, 0);
echo $sum; // Outputs: 15
Utilize array_reduce() to aggregate array data, such as summing numbers.
$numbers = [1, 2, 3, 4, 5];
$sum = array_reduce($numbers, function($carry, $item) { return $carry + $item; }, 0);
echo $sum; // Outputs: 15