Popping the key & value from an associative array in PHP

前端 未结 4 1704
梦谈多话
梦谈多话 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:54

    list($value, $key) = array(reset($s), key($s));
    array_shift($s); // or just unset($s[$key]);
    

    Of course you can split the first statement into two separate.

提交回复
热议问题