Example 1 — Add Up Numbers
Sum a short list of whole numbers.
<?php
$numbers = [2, 4, 6];
$total = array_sum($numbers);
echo "Total: ", $total, PHP_EOL; How It Works
- Create an array with the numbers 2, 4 and 6.
- array_sum() adds them: 2 + 4 + 6.
- The total, 12, is stored in $total.
- echo prints the result.

