There are two types of arrays in PHP, indexed and associative arrays. In case of indexed array strict numeric indexing is followed but in case of associative array there are keys corresponding to each element.
The elements of an associative array can only be accessed by the corresponding keys. As there is not strict indexing between the keys, accessing the elements normally by integer index is not possible in PHP.
Although the array_keys() function can be used to get an indexed array of keys for an associative array. As the resulting array is indexed the elements of the resulting array can be accessed by integer index. Using this resulting array, the keys of the original array can be accessed by integer index and then the keys can be used to access the elements of the original array. Thus by using the integer index the elements of the original array can be accessed with the help of an additional indexed array of keys.
array_keys() function: The array_keys() function takes an array as input and returns an indexed array which consists only the keys of the original array, indexed where indexing is started from zero.
array array_keys( $arr )
Parameters: The array_keys() function takes an array as input and use only the keys of the array to make the indexed resulting array.
Note: The array_keys() function does not change the order of the keys of the original array. If an indexed array is passed then the resulting array will have integers as value.
Program: PHP program to access an associative array using integer index.
The keys array: Array (  => one  => two  => three ) The elements of the sample array: key: one, value: geeks key: two, value: for key: three, value: geeks
- How to get numeric index of associative array in PHP?
- Multidimensional Associative Array in PHP
- How to loop through an associative array and get the key in PHP?
- How to remove a key and its value from an associative array in PHP ?
- How to check an array is associative or sequential in PHP?
- Convert an object to associative array in PHP
- Iterate associative array using foreach loop in PHP
- PHP program to add item at the beginning of associative array
- How to merge the first index of an array with the first index of second array?
- How to get Synchronize access to the Array in C#
- Associative Arrays in PHP
- How to re-index an array in PHP?
- Find the index of an array element in Java
- How to use Array Reverse Sort Functions for Integer and Strings in Golang?
- PHP | Access Specifiers
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.