How to get numeric index of associative array in PHP? Last Updated : 30 Apr, 2019 Comments Improve Suggest changes Like Article Like Report In PHP we can associate name/label with each array elements using => symbol. This is very helpful as it is easy to remember the element because each element is represented by the label rather than the index value. Using array_keys() function: The array_keys() function is an inbuilt function in PHP which is used to return either all the keys of an array or the subset of the keys. Syntax: array array_keys( $input_array, $search_value, $strict ) Program 1: Program to get numeric index of associative array using array_keys() function. php <?php // Program to print index of an associative array // Declare an associative array $assoc_array=array("Geeks"=>10, "for"=>15, "geeks"=>20); // Print index with corresponding key // using array_keys() function print_r(array_keys($assoc_array)); ?> Example 2: Below program uses index to access the values in associative array. php <?php // Program to print values using index // of associative array // Declare an associative array $assoc_array = array( "Geeks" => 30, "for" => 20, "geeks" => 10 ); // Using array_keys() function $key = array_keys($assoc_array); // Calculate size of array $size = sizeof($key); // Using loop to access values for( $i = 0; $i < $size; $i++) { echo "${assoc_array[$key[$i]]}\n"; } ?> Comment More infoAdvertise with us Next Article How to get numeric index of associative array in PHP? R Rajnis09 Follow Improve Article Tags : Web Technologies PHP PHP Programs Similar Reads How to Get All Keys of an Associative Array in PHP? Given an Associative array, the task is to get all the keys of the associative array in PHP. There are two approaches to get all keys from the associative array, these are - using array_keys(), and foreach loop. In this article, we will explore these approaches with examples.Table of ContentApproach 2 min read How to access an associative array by integer index in PHP? 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 th 3 min read How to Check if a Key Exists in an Associative Array in PHP? Given an Associative array, the task is to check whether a key exists in the associative array or not. There are two methods to check if a key exists in an associative array, these are - using array_key_exists(), and isset() functions. Let's explore each method with detailed explanations and code ex 3 min read How to Get first N number of Elements From an Array in PHP? Given an array, the task is to get the first N number of elements from the array in PHP. There are various approaches to achieve this task. In this article, we will explore all approaches with detailed explanations.These are the following approaches:Table of Content Using array_slice() FunctionUsing 3 min read How to loop through an associative array and get the key in PHP? Associative arrays are used to store key-value pairs. For example, to store the marks of the different subject of a student in an array, a numerically indexed array would not be the best choice. Instead, we could use the respective subjectâs names as the keys in our associative array, and the value 3 min read Like