Numeric Arrays
A numeric array stores each element with a numeric ID key.
There are different ways to create a numeric array.
Example 1
In this example the ID key is automatically assigned:
$names = array("Peter","John","Joe");
Example 2
In this example we assign the ID key manually:
$names[0] = "Peter";
$names[1] = "John";
$names[2] = "Joe";
The ID keys can be used in a script:
<?php
$names[0] = "Peter";
$names[1] = "John";
$names[2] = "Joe";
echo $names[1] . " and " . $names[2] . " are ". $names[0] . "'s neighbours";
?>
The code above will output:
John and Joe are Peter's neighbours.
Back to Home
|