An array is the same as
variable except that it can store multiple values using an index key.
Here’s an example:
<?php
$names = array("John", "Peter", "Matthew", "Andrew")
echo "The following are biblical name: " . names[0] . ", " . names[1] . ", " . names[2] . ", " . names[3] . ".";
?>
You can also directly assign a value into an array with its index key, example:
<?php
$names[0] = "John";
$names[1] = "Peter";
$names[2] = "Matthew";
$names[3] = "Andrew";
echo "The following are biblical name: " . names[0] . ", " . names[1] . ", " . names[2] . ", " . names[3] . ".";
?>
The above example is using number as an index key. You can also use named key to identify an array easily.
Consider the following example:
<?php
$name["John"] = 35;
$name["Peter"] = 28;
$name["Matthew"] = 31;
$name["Andrew"] = 34;
echo "John’s age is: " . $name["John"];
?>
An associative array is very useful if you want to access your table’s record using a field name.
Example:
<?php
echo $table["name"];
echo $table["address"];
?>