PHP Create Arrays
In PHP, you can create arrays in several ways depending on the type of array you need: indexed, associative, or multidimensional.
1. Indexed Arrays
These arrays use numeric indexes starting from 0.
Or using short syntax (PHP 5.4+):
2. Associative Arrays
These arrays use named keys that you assign to them.
Or with short syntax:
3. Multidimensional Arrays
Arrays containing one or more arrays.
Tips:
-
Use
print_r($array)
orvar_dump($array)
to inspect arrays. -
You can add values like this: