← PHP learning pathPHP · Module 3 of 10
Arrays and control flow
Work with arrays and loops.
📖 Key ideas
- Indexed arrays: $a = [1, 2, 3];
- Associative arrays: $user = ["name" => "Asha", "age" => 21];
- foreach ($items as $key => $value) loops arrays.
- if/elseif/else, switch, match (PHP 8).
- 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