It is difficult to conclude from the PHP manual regarding the use of the search_value parameter. I needed to try an example.
If the optional search_value is specified, then only the keys for **that** value are returned. Otherwise, all the keys from the input are returned.
This means that when search_value specified in array_keys() , values ββin the array (not keys) are executed using search_value . If a match occurs, the key for this value is search_value in search_value .
Example
<? $foo = array('first' => 'my_first', 'second' => 'my_second', 'third' => 'my_third', 'fourth' => null); $keys = array_keys($foo); var_dump($keys); //Output 0 $keys = array_keys($foo, 'my_second'); var_dump($keys); //Output 1 $keys = array_keys($foo, null); var_dump($keys); //Output 2 ?>
Output
0
array(4) { [0]=> string(5) "first" [1]=> string(6) "second" [2]=> string(5) "third" [3]=> string(6) "fourth" }
1
array(1) { [0]=> string(6) "second" }
2:
array(1) { [0]=> string(6) "fourth" }
source share