array / [ ]
Try it yourself →Creates a collection of values.
Syntax
$name = [e1, e2, ...];
Description
Arrays are created using square brackets. Elements are accessed with 0-based indexing.
Example
<?php $colors = ["red", "purple", "green"]; echo $colors[0]; echo "\n"; echo count($colors);
Expected output
red 3
When to use?
Holding lists (names, products).
Common mistakes
- ⚠️ Indexing starts at 0: the first element is $arr[0].