array_shift but preserve keys

前端 未结 4 1134
小鲜肉
小鲜肉 2021-01-17 09:41

My array looks like this:

$arValues = array( 345 => \"jhdrfr\", 534 => \"jhdrffr\", 673 => \"jhrffr\", 234 => \"jfrhfr\" );

How

4条回答
  •  离开以前
    2021-01-17 10:04

    This works fine for me...

    $array = array('1','2','3','4');
    
    reset($array);
    $key = key($array);
    $value = $array[$key];
    unset($array[$key]);
    
    var_dump($key, $value, $array, current($array));
    

    Output:

    int(0) 
    string(1) "1" 
    array(3) { [1]=> string(1) "2" [2]=> string(1) "3" [3]=> string(1) "4" }
    string(1) "2"
    

提交回复
热议问题