2. • A variable of the storage area holding a number or text.
• Array will hold only ONE value.
• An array is a special variable, which can store multiple value in one single
variable.
• If you have a list of items (a list of car names, for example), storing the cars
in the single variables look like this :
• An array can hold all your variable value under a single name and you can
easily accessed the value by referring to the array name.
• Each element in the array has its own index so that it can be easily
accessed.
WHAT IS ARRAY?
<?php
$car1 = “Saab”;
$car2 = “Volvo”;
$car3 = “BMW”;
?>
3. TYPES OF ARRAY
04
01 Numeric Array
An array with a numeric arrays.
02 Associative Array
An array where each ID key is associated with a value.
03 Multidimensional Array
An array containing one or more arrays.
4. A numeric array stores each array element with a numeric index.
There are 2 methods to create a numeric array.
1. In the following example the index are automatically assigned (the index
starts at 0):
2. In the following example we assigned the index manually:
NUMERIC ARRAYS
<?php
$cars = array(“Saab”, “Volvo, ”BMW”, “Toyota”);
?>
<?php
$cars[0] = “Saab”;
$cars[1] = “Volvo”;
$cars[2] = “BMW”;
$cars[3] = “Toyota”;
?>
5. In the following example you access the variable values by referring to the
array name and index:
1. The code above will show the output:
NUMERIC ARRAYS
Proton Exora and Inokom are Malaysian cars.
<?php
$cars[0] = “Proton Exora”;
$cars[1] = “Volvo”;
$cars[2] = “Inokom”;
$cars[3] = “Toyota”;
echo $cars[0] . “ and ” . $cars[2] . “ are Malaysian cars”;
?>