English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The PHP array_keys() function returns partial or all key names in the array
array_keys( $input[, $search_value[, $strict]]);
array_keys() returns the key names of numbers or strings in the input array.
If the optional parameter search_value is specified, only the key names of that value are returned. Otherwise, all key names in the input array are returned.
Serial Number | Parameters and Description |
---|---|
1 | input(Required) It specifies an array. |
2 | search_value(Required) You can specify a value and only return the keys that have that value. |
3 | strict Optional. Used together with the value parameter. |
It returns keys, numbers, and strings from the $input array
Returns all keys in the array and the key of the specified value
<?php $input = array("a" => "Monkey", "b" => "Cat", "c" => "Dog"); print_r(array_keys($input)); $input = array("a" => "Monkey", "b" => "Cat", "c" => "Dog"); print_r(array_keys($input, "Dog")); $input = array(10,20,30, "10"); print_r(array_keys($input, "10", false)); ?>Test and see‹/›
Output result:
Array ( [0] => a [1] => b [2] => c ) Array ( [0] => c ) Array ( [0] => 0 [1] => 3 )