PHP · Learn

The PHP curriculum

PHP is a server-side language that powers a large share of the web, from WordPress and Laravel applications to plain templated sites and JSON APIs, and it runs anywhere a web host does. This curriculum starts with the syntax, types, loops, functions and arrays you need for any script, moves on to strings, associative arrays, sorting and classes, and finishes with exceptions and JSON handling, the two skills every real PHP backend depends on. Every example is verified against PHP 8.4, and every exercise reads standard input and prints to standard output, so what you write here works unchanged on the command line.

lessons
9 lessons
hours of reading
1.4 hours of reading
exercises to practise
14 exercises to practise

Beginner

5 lessons · about 40 minutes of reading, plus practice.

  1. PHP Syntax and Your First ProgramHow a PHP script is put together: the opening tag, statements and semicolons, echo, comments, and reading one line of input with fgets(STDIN) in PHP 8.4.7 min
  2. Variables and Types in PHPHow PHP variables are named and assigned, the scalar types int, float, string, bool and null, how input text becomes numbers, and where type juggling bites.8 min
  3. Conditions and Loops in PHPBranch with if, elseif, else and match, repeat with while, for and foreach, and control loops with break and continue, with PHP 8 examples that read input.9 min
  4. Functions in PHPDefine PHP functions with typed parameters and return types, use default values, named arguments and variadics, and see why variables inside a function are.10 min
  5. Arrays in PHPHow PHP arrays hold ordered lists: literals, indexing, appending, count, foreach, searching, slicing and the array_map, array_filter and array_sum helpers.9 min

Intermediate

2 lessons · about 20 minutes of reading, plus practice.

  1. Strings in PHPSingle and double quotes, interpolation and heredoc, the string functions you reach for daily, multibyte text with mb_ functions and sprintf formatting in PHP.10 min
  2. Associative Arrays and Sorting in PHPUse string keys to model records in PHP, check keys safely, tally and group data, and sort by value, key or a custom rule with sort, asort, ksort and usort.10 min

Advanced

2 lessons · about 20 minutes of reading, plus practice.

  1. Exceptions and Error Handling in PHPThrow and catch PHP exceptions, write custom exception classes, use finally for cleanup, tell Error from Exception, and turn warnings into exceptions with.11 min
  2. JSON and Data Handling in PHPEncode PHP arrays to JSON and decode JSON into arrays, choose the right flags, avoid the list-versus-object trap, and turn raw input lines into structured.11 min