3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Display a welcome message echo "Welcome to PHP programming!"; // Variables in PHP $name = "John"; $age = 25; // Output variables echo "<br>Name: $name"; echo "<br>Age: $age"; // Conditional statement if ($age > 18) { echo "<br>$name is an adult."; } else { echo "<br>$name is not an adult."; } // Loop example echo "<br>Numbers from 1 to 5:"; for ($i = 1; $i <= 5; $i++) { echo " $i"; } // Function example function greet($person) { return "<br>Hello, $person!"; } echo greet($name); // Associative array and foreach loop $personDetails = [ "Name" => $name, "Age" => $age, "Country" => "USA" ]; echo "<br><br>Person Details:"; foreach ($personDetails as $key => $value) { echo "<br>$key: $value"; } ?>
Output for 8.2.0 - 8.2.27, 8.3.0 - 8.3.16, 8.4.1 - 8.4.3
Welcome to PHP programming!<br>Name: John<br>Age: 25<br>John is an adult.<br>Numbers from 1 to 5: 1 2 3 4 5<br>Hello, John!<br><br>Person Details:<br>Name: John<br>Age: 25<br>Country: USA

preferences:
44.32 ms | 406 KiB | 5 Q