Getting the key of the only element in a PHP array

前端 未结 6 833
暖寄归人
暖寄归人 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:20

    Shortest, easiest and most independent solution is:

    $key   = key($arr);
    $value = reset($arr);
    

提交回复
热议问题