PHP Array Example

This PHP example uses arrays, foreach, and array_sum. It is a clean first exercise for checking PHP WebAssembly output in the browser terminal.

PHP Compiler

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

  1. Open the PHP compiler and paste the code.
  2. Run it and inspect each echo line.
  3. Add another value or wrap the total logic in a function.
HOME LEARN COMMUNITY DASHBOARD