An array holds many values in a single variable. Instead of $color1, $color2 and $color3, you keep one list.
<?php
$colors = ["red", "green", "blue"];
echo $colors[0] . "\n";
echo $colors[2];
red
blue
Positions start at 0, so the first item is [0].
Arrays with names
An associative array uses names (keys) instead of numbers.
<?php
$user = [
"name" => "Isha",
"age" => 31,
"city" => "Indore",
];
echo $user["name"] . " lives in " . $user["city"];
Isha lives in Indore
Looking inside an array
Use print_r() for a quick, readable look.
<?php
$tags = ["php", "web"];
print_r($tags);
Array
(
[0] => php
[1] => web
)
var_dump() shows more detail (types and sizes). Both are for debugging, not for the visitor.
How many items?
<?php
echo count(["a", "b", "c"]);
3
Arrays can hold anything
Items can be of different types, and an array can even contain other arrays. Multidimensional Arrays covers that.