Popping the key & value from an associative array in PHP

前端 未结 4 1705
梦谈多话
梦谈多话 2021-02-07 00:14

Let S be an associative array in PHP, I need to retrieve and extract from it the first element, both the value and the key.

I would use

value1=array_pop         


        
4条回答
  •  庸人自扰
    2021-02-07 00:33

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

    Edit: Hakre just beat me to it :-)

提交回复
热议问题