A numeric array stores each array element with a numeric index.
There are two methods to create a numeric array.
1. In the following example the index are automatically assigned (the index starts at 0):
| $cars=array("Saab","Volvo","BMW","Toyota"); |
2. In the following example we assign the index manually:
| $cars[0]="Saab"; $cars[1]="Volvo"; $cars[2]="BMW"; $cars[3]="Toyota"; |
Example
In the following example you access the variable values by referring to the array name and index:
| <?php $cars[0]="Saab"; $cars[1]="Volvo"; $cars[2]="BMW"; $cars[3]="Toyota"; echo $cars[0] . " and " . $cars[1] . " are Swedish cars."; ?> |
The code above will output:
| Saab and Volvo are Swedish cars. |
0 comments:
Post a Comment