PHP arrays are ordered maps—they work as lists (0-based indices) and as dictionaries. An indexed array behaves like a JavaScript array of values.
Creating and accessing
$tags = ['php', 'web', 'backend'];
echo $tags[0]; // php
$tags[] = 'laravel'; // append
count($tags); // length
Zero-based indexing
First element is index 0. Accessing an undefined index emits a notice/warning in modern PHP—check with isset($arr[$i]) or null coalescing.
Spread operator (PHP 7.4+)
$a = [1, 2];
$b = [...$a, 3]; // [1, 2, 3]
Self-check
- How do you append without knowing the next index?
- What function returns the number of elements?