Getting the key of the only element in a PHP array

前端 未结 6 821
暖寄归人
暖寄归人 2021-01-17 12:17

The key of the associative array is dynamically generated. How do I get the \"Key\" of such an array?

$arr = array (\'dynamic_key\' => \'Value\');
         


        
6条回答
  •  醉梦人生
    2021-01-17 13:03

    do you mean that you have the value of entry and want to get the key ?

    array_search ($value, $array) 
    

    Returns the key for needle if it is found in the array, FALSE otherwise.

    If needle is found in haystack more than once, the first matching key is returned. To return the keys for all matching values, use array_keys() with the optional search_value parameter instead.

    more details : http://php.net/manual/en/function.array-search.php

提交回复
热议问题