← PHP learning path
PHP · Module 3 of 10

Arrays and control flow

Work with arrays and loops.

📖 Key ideas

  1. Indexed arrays: $a = [1, 2, 3];
  2. Associative arrays: $user = ["name" => "Asha", "age" => 21];
  3. foreach ($items as $key => $value) loops arrays.
  4. if/elseif/else, switch, match (PHP 8).
  5. Useful functions: count, in_array, array_map, array_filter, sort.
💡 Real-life example: An associative array is a labelled cupboard: each drawer has a name instead of a number.
Indexed arrayNumbered keys
Associative arrayNamed keys
foreachLoops arrays
matchExpression-based switch in PHP 8