An array is a data structure widely used in almost all programming languages, including PHP. An array contains a group of elements, and every element has an index or key. An array can be one-dimensional or multidimensional. Today, we will learn two different ways to declare an array in PHP. I prefer the second one because it helps me to read the code easily.
This is the conventional method of declaring an array in PHP.
// First way $cars = array("audi", "volvo", "mazda", "toyota", "BMW"); print_r($cars);
This is the short-hand version of declaring an array in PHP. This syntax was introduced in PHP 5.4.0
// second way $cars = ["audi", "volvo", "mazda", "toyota", "BMW"]; print_r($cars);