Add to an array using index in PHP
Description
The following code shows how to add to an array using index.
Example
/*from w w w .j a v a 2s. c o m*/
<?php
$Cities[] = "A";
$Cities[] = "B";
$Cities[] = "C";
$Cities[] = "D";
// count number of elements
$indexLimit = count($Cities);
// print out every element
for($index=0; $index < $indexLimit; $index++)
{
print("City $index is $Cities[$index]. <br>\n");
}
?>
The code above generates the following result.