Skip to content

PHP practice

Practice PHP online: 10 exercises, graded problems and a playground

PHP normally needs a web server before you can see anything; here the real PHP interpreter is compiled to WebAssembly and runs your script directly in the browser, printing to the output panel instead of a page. Every exercise starts with the <?php tag and uses echo, variables, loops and arrays the way a command-line PHP script would, so what you learn transfers straight to server code.

checked exercises
10
graded problems
0
lessons
0
cheat sheet (coming)
0

PHP practice exercises

How the path works →

In order, each one introducing a single new idea. Press Run to check your answer; hints open one at a time.

  1. First Lines of PHPecho prints text, and every statement ends with a semicolon
  2. Greet By Namea variable stores a value under a name starting with $
  3. Ticket Totalarithmetic operators (+ - * /) and joining text with .
  4. Open or Closedif/else with && requiring every part of a condition to be true
  5. Launch Countdowna for loop repeats a block a set number of times
  6. Even Numbers Onlyan if inside a for loop, decided again on every pass
  7. Score Reportsprintf() builds a formatted string from a template
  8. Packing Listan array holds several values, and foreach walks through them
  9. Total Weighta variable before a loop can carry a running total
  10. Trip Summaryassembling a complete program from parts you already know

Coding interview questions

Original questions with full model answers, for when the practice is going somewhere specific.

Questions people ask

Is this real PHP, and which version?
Real PHP 8.4, compiled to WebAssembly by the php-wasm project. Parse errors and fatal errors are PHP's own messages, line numbers included.
Can I read input with fgets(STDIN)?
Yes. The input box beside the editor is the script's standard input, and fgets(STDIN) reads it one line at a time exactly as it would from a terminal.
Why does every exercise start with <?php?
Because PHP treats anything outside that tag as plain text to print, and a script that forgets it silently echoes its own source. Seeing the tag on line 1 of every exercise builds the habit before it costs you an afternoon.
What comes after these exercises?
Beyond the 10 exercises: a blank playground for anything you want to try next.

Practise another language

The same kind of practice hub exists for Python, JavaScript, TypeScript, Java, C++, C, C#, Go, Ruby, SQL, R and Bash & the Shell.