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
array_slice
$arr = array('k1' => 'v1', 'k2' => 'v2', 'k3' => 'v3'); $a = array_slice($arr, 0, 1); var_dump($a); $arr = array_slice($arr, 1); var_dump($arr); array(1) { ["k1"]=> string(2) "v1" } array(2) { ["k2"]=> string(2) "v2" ["k3"]=> string(2) "v3" }