You can create arrays using the array() function:
$cars |
You can also use a shorter syntax with the [ ] brackets:
$cars |
Line breaks are not significant, allowing an array declaration to span multiple lines:
$cars |
A comma after the last item is permissible:
$cars |
When creating indexed arrays, keys are assigned automatically, starting at 0 and increasing by 1 for each item. Therefore, the array above could also be defined with explicit keys:
$cars |
As you can see, indexed arrays are similar to associative arrays, but associative arrays use names instead of numbers:
$myCar
];
|
You can create an empty array initially and add items to it later:
$cars |
The same applies to associative arrays; you can declare the array first and then add items to it later:
$myCar |
You can have arrays that contain both indexed and named keys:
$myArr |