本文介绍了PHP重新索引数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
再次请原谅我的noobness。我有一个数组在它20+的价值观和我采取每20在我的数据库来推,然后他们剁成关闭阵列的前端。我要重新启动阵列的指标回到0,而是在20开始,甚至当我用array_values。我也试过array_merge(数组(),$字符串),怎么办?
如果($ X%20 == 0){
后续代码var_dump($字符串)//原数组
get_string($字符串,$机构,$二进制); //把20串入我的数据库 为($ Y = 0; $ Y< 20; $ Y ++)//使用20这样做我删除它们
未设置($字符串[$ Y]); array_values($字符串); //重新索引集$字符串[20]到$字符串[0]请!
后续代码var_dump($字符串); //这是假设重建索引
}
相反,我得到
//阵原数组
0 =>字符串'----'(长度= 25)
1 =>字符串'----'(长度= 15)
2 =>字符串'----'(长度= 27)
3 =>字符串'----'(长度= 22)
4 =>字符串'----'(长度= 23)
5 =>字符串'----'(长度= 21)
6 =>字符串'----'(长度= 26)
7 =>字符串'----'(长度= 23)
8 =>字符串'----'(长度= 24)
9 =>字符串'----'(长度= 31)
10 =>字符串'----'(长度= 19)
11 =>字符串'----'(长度= 22)
12 =>字符串'----'(长度= 24)
13 =>字符串'----'(长度= 24)
14 =>字符串'----'(长度= 25)
15 =>字符串'----'(长度= 12)
16 =>字符串'----'(长度= 16)
17 =>字符串'----'(长度= 15)
18 =>字符串'----'(长度= 23)
19 =>字符串'----'(长度= 15)
20 =>字符串'----'(长度= 16)
21 =>字符串'----'(长度= 27)数组//重建索引数组?这被假设为[0],[1]
20 =>字符串'----'(长度= 16)
21 =>字符串'----'(长度= 27)
解决方案
我通常做的:
$阵列= array_values($数组);
看起来就像你最有路 - 只是忘到新数组旧变量分配
Forgive my noobness again. I've got an array with 20+ values in it and I take every 20 to shove in my database and then chop them off the front of the array. I want to restart the array's indexes back to 0 but instead it starts at 20 even when I use array_values. I also tried array_merge(array(), $string) What to do?
if($x%20 == 0){
var_dump($string) // original array
get_string($string, $body, $binary); //puts the 20 string into my db
for($y=0; $y <20; $y++) //done with the 20 so I'm removing them
unset($string[$y]);
array_values($string); //reindex set $string[20] to $string[0] PLEASE!
var_dump($string); // this is suppose to be reindexed
}
Instead I get
array // original array
0 => string '----' (length=25)
1 => string '----' (length=15)
2 => string '----' (length=27)
3 => string '----' (length=22)
4 => string '----' (length=23)
5 => string '----' (length=21)
6 => string '----' (length=26)
7 => string '----' (length=23)
8 => string '----' (length=24)
9 => string '----' (length=31)
10 => string '----' (length=19)
11 => string '----' (length=22)
12 => string '----' (length=24)
13 => string '----' (length=24)
14 => string '----' (length=25)
15 => string '----' (length=12)
16 => string '----' (length=16)
17 => string '----' (length=15)
18 => string '----' (length=23)
19 => string '----' (length=15)
20 => string '----' (length=16)
21 => string '----' (length=27)
array //reindexed array? This was suppose to be [0] and [1]
20 => string '----' (length=16)
21 => string '----' (length=27)
解决方案
I usually do:
$array = array_values($array);
Looks like you got most of the way there - just forgot to assign the new array to the old variable.
这篇关于PHP重新索引数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!