Array is an single variable that holds multiple values. In an array you can store the related values into a single variable.
If you have a list of items like (banana,apple,orange), then storing the fruits in a single variable could look like this:
If you want to store 3 values is no problem. When it goes upto 100 or 200 then there may be a problem raised. The best solution to avoid this is to use an Array.
In PHP, there are three kinds of arrays. They are
Numeric arrays - An array with numeric index
Associative array - An array where each ID key is associated with a value.
Multi dimensional array - An array containing one or more arrays.
In PHP, there are 2 ways to create a numeric array
1. Index are automatically assigned. Example
2. Assign the indexes manually. Example
In an associative array each ID key is associated with a value.
When storing data about specific named values, a numerical array is not always the best way to do it.
With associative arrays we can use the values as keys and assign values to them.
There are 2 ways to create an associative array
$age = array("Kennedy"=>32, "Lincoln"=>30, "Bush"=>34);
2.,ID keys are used in a script
$ages['Kennedy'] = "32";
$ages['Lincoln'] = "30";
$ages['Bush'] = "34";
echo "Kennedy is " . $ages['kennedy'] . " years old.";
Kennedy is 32 years old.