The array_keys() is a built-in function in PHP and is used to return either all the keys of and array or the subset of the keys.
array array_keys($input_array, $search_value, $strict)
Parameters: The function takes three parameters out of which one is mandatory and other two are optional.
- $input_array (mandatory): Refers to the array that we want to operate on.
- $search_value (optional): Refers to the value of the array by which we want to search the array for the key elements. If this parameter is passed then the function will return keys coressponding to this element only otherwise it will return all keys of the array.
- $strict (optional): Determines if strict comparison (===) should be used during the search. false is the default value.
Return Value: The function returns an array containing either all of the keys or subset of keys the input array depending upon the parameters passed.
Input : $input_array = ("one" => "shyam", 2 => "rishav", "three" => "gaurav") Output : Array (  => one  => 2  => three ) Input : $input_array = ("one", "two", "three", "one", "four", "three", "one", "one") $search_value = "one" Output : Array (  => 0  => 3  => 6  => 7 )
In the below program, we have passed a simple associative array to the function array_keys(), to print all of its keys:
Array (  => one  => 2  => three )
In the below program, along with the array we have passed a value only for which the key position is returned.
Array (  => 0  => 3  => 6  => 7 )
- How to get the function name inside a function in PHP ?
- PHP | next() Function
- PHP | each() Function
- PHP | exp() Function
- PHP | Ds\Map get() Function
- PHP | tan( ) Function
- p5.js | red() function
- PHP | pow( ) Function
- D3.js | d3.set.add() Function
- p5.js | pan() Function
- D3.js | d3.hsl() Function
- p5.js | min() function
- D3.js | d3.min() function
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.