PHP array_keys() Function
Last Updated : 17 Mar 2025
The array_keys() function is used to get all the keys or a subset of the keys of an array. It returns the keys, numeric and string, from the input array. This function was introduced in PHP 4.0.
Syntax
Parameter
| Parameter | Description | Is compulsory |
|---|---|---|
| array | Specifies an array. | compulsory |
| search_value | Specify a value, then only the keys with this value are returned. | Optional |
| strict | Determines if strict comparison (===) should be used during the search. | Optional |
Return Type
The array_keys( ) function returns an array containing the keys.
EXAMPLE 1
Output:
Array ( [0] => virat [1] => sachin [2] => ganguly [3] => rahul )
EXAMPLE 2
Output:
Array ( [0] => a [1] => b [2] => c )
EXAMPLE 3
Output:
Array ( [0] => c )
EXAMPLE 4
Output:
Array ( [0] => 3 )
Next TopicPhp-array-krsort-function