These arrays can store numbers, strings and any object but their index will be prepresented by numbers. By default array index starts from zero.
Example
Following is the example showing how to create and access numeric arrays.
Here we have used array() function to create array. This function is explained in function reference.
<html> <body> <?php /* First method to create array. */ $numbers = array( 10,9,8,7,6); foreach( $numbers as $value ) { echo "Value is $value <br />"; } /* Second method to create array. */ $numbers[0] = "one"; $numbers[1] = "two"; $numbers[2] = "three"; $numbers[3] = "four"; $numbers[4] = "five"; foreach( $numbers as $value ) { echo "Value is $value <br />"; } ?> </body> </html> |
This will produce following result:
Value is 10 Value is 9 Value is 8 Value is 7 Value is 6 Value is one Value is two Value is three Value is four Value is five