Arrays in PHP
In this lesson, we will begin to study a special data type called array. An array is a variable in which you can store a whole set of some values in an orderly manner.
Square brackets are used to create an array:
<?php
$arr = []; // create an array $arr
?>
So far, the array we created does not contain any data. Let's fill it with strings:
<?php
$arr = ['a', 'b', 'c'];
?>
Each value in the list that we wrote into the array is called an element of the array. As you can see, the elements are separated from each other by a comma. You can put spaces after this comma, or you can not put them (it is more common to put them, so put them).
You can also store numbers in an array:
<?php
$arr = [1, 2, 3];
?>
In addition to strings and numbers, you can store all valid PHP data types in an array, and also mix them together in one array, example:
<?php
$arr = [1, 2, 'a', 'b', null, true, false];
?>