Code Example
<?php
$prices = [120, 250, 80];
$total = array_sum($prices);
foreach ($prices as $price) {
echo "Price: $price\n";
}
echo "Total: $total\n";
?>
Expected Output
Price: 120
Price: 250
Price: 80
Total: 450
Practice Steps
- Open the PHP compiler and paste the code.
- Run it and inspect each echo line.
- Add another value or wrap the total logic in a function.