Scalar variables store only one value at a time. They cannot store a list of values.
Arrays are special types of variables which can store a list of values at a time.
An array can include a list of days in a week.
Arrays are indexed; each entry contains a key and a value.
Here, the values stored in array are known as elements.
Each element is referenced by an index that identifies the element by any unique element in the array.
Co-operate in keeping internet open, free, fluid, live and one by contributing your one-day-income via PayPal to email@example.com that is reinventing business, technology and media of new millennium.
The index value can be a number or string but it should be unique.
Associative and Numeric Arrays:
Numeric arrays use numbers as their indexes.
Associative arrays use strings as their indexes.
An example of numeric array:
An example of associative array:
Internally PHP stores the numeric array same as the associative array.
How to create an array:
An array can be created by the array() function or the array operator .
The following example shows how to create an array called $week using the array() function, containing all days of the week:
$week = array(“Monday”, “Tuesday”, Wednesday”, “Thursday”, Friday”, “Saturday”, “Sunday”);
If you create an array using array function then also you an list the last elements using an array operator:
$week = array(“Monday”, “Tuesday”, Wednesday”, “Thursday”, Friday”, “Saturday”);
$week = “Sunday”;
Following is the same array created by using an array operator:
$week = “Monday”;
$week = “Tuesday”;
$week = “Wednesday”;
$week = “Thursday”;
$week = “Friday”;
$week = “Saturday”;
$week = “Sunday”;
In case if you misnumber your elements then PHP will arrange them in correct way.