PHP Arrays
PHP array is an ordered map (contains value on the basis of the key). It is used to hold multiple values of a similar type in a single variable.

Advantage of PHP Array
- Less Code: We don't need to define multiple variables.
- Easy to traverse: With the help of the single loop, we can traverse all the elements of an array.
- Sorting: We can sort the elements of array.
What are PHP Arrays
Arrays are complex variables that allow us to store more than one value or a group of values under a single variable name. Let's suppose you want to store colors in your PHP script. Storing the colors one by one in a variable could look something like this:
Example :
<?php
$day1= "Sunday";
$day2 = "Monday";
$day3 = "Tuesday";
?>
If you want to store the states or city names of a country in variables and this time this not just three maybe a hundred. It is quite hard, boring, and a bad idea to store each city name in a separate variable. And here array comes into play.
Create an Array in PHP
In PHP, the array() function is used to create an array:
array();
Types of Arrays in PHP
There are three types of arrays that you can create. These are:
- Indexed array — An array with a numeric key.
- Associative array — An array where each key has its own specific value.
- Multidimensional array — An array containing one or more arrays within itself.
