array_shift 但保存钥匙

我的数组看起来像这样:


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


如何删除数组的第一个元素,但保存数字键? 因为
array_shift

更改我的整数键值
0, 1, 2, ...

.

我试着用
unset/ $arValues[ $first ] /; reset/ $arValues /;

, 继续使用第二个元素 /现在是第一个/, 但他回来了
false

.

我怎样才能实现这一目标?
已邀请:

二哥

赞同来自:

reset/ $a /;
unset/ $a[ key/$a/]/;


有点有用的版本:


// rewinds array's internal pointer to the first element
// and returns the value of the first array element.
$value = reset/ $a /;

// returns the index element of the current array position
$key = key/ $a /;

unset/ $a[ $key ]/;


功能:


// returns value
function array_shift_assoc/ &$arr /{
$val = reset/ $arr /;
unset/ $arr[ key/ $arr / ] /;
return $val;
}

// returns [ key, value ]
function array_shift_assoc_kv/ &$arr /{
$val = reset/ $arr /;
$key = key/ $arr /;
$ret = array/ $key => $val /;
unset/ $arr[ $key ] /;
return $ret;
}

莫问

赞同来自:

// 1 is the index of the first object to get
// NULL to get everything until the end
// true to preserve keys
$arValues = array_slice/$arValues, 1, NULL, true/;

窦买办

赞同来自:

function array_shift_associative/&$arr/{
reset/$arr/;
$return = array/key/$arr/=>current/$arr//;
unset/$arr[key/$arr/]/;
return $return;
}


此功能使用该方法 biziclop, 但回来了一对夫妇
key=>value

.

涵秋

赞同来自:

这对我很有效 ...


$array = array/'1','2','3','4'/;

reset/$array/;
$key = key/$array/;
$value = $array[$key];
unset/$array[$key]/;

var_dump/$key, $value, $array, current/$array//;


出口:


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

要回复问题请先登录注册