The array_keys() function returns an array containing the keys.
Note: If the optional search_key_value is specified, then only the keys for that value are returned. Otherwise, all the keys from the array are returned.
Parameter | Description |
---|---|
array | Required. Specifies an array |
value | Optional. You can specify a value, then only the keys with this value are returned |
strict | Optional. Used with the value parameter. Possible values:
|
Syntax
array_keys(array,value,strict)
Example
$array=array("a"=>"Prince","b"=>"Samuel","c"=>"Cooper");
print_r(array_keys($array,"Cooper"));
Output
Array ( [0] => c )
More Example
$array=array(4,5,6,"5");
print_r(array_keys($array,"5",false));
Output
Array ( [0] => 1 [1] => 3 )