Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 阵列_diff&;重新编号数字键_Php_Arrays_Key_Numeric - Fatal编程技术网

Php 阵列_diff&;重新编号数字键

Php 阵列_diff&;重新编号数字键,php,arrays,key,numeric,Php,Arrays,Key,Numeric,我的脚本使用标准 (I'm a beginner) $c=0; $t=计数($array); 而($c

我的脚本使用标准

(I'm a beginner)
$c=0;
$t=计数($array);
而($c<$t){
$blah=$array[$c];
++$c;
}
相当广泛。但我刚刚遇到了一个情况,我还需要
数组_diff
,它打破了这一切,因为现在数字键有间隙。我到处都是
未定义的偏移量
错误


如何重置数组的数字键?数组中对象的顺序无关。

要重置键,可以使用:


您不需要重置数组的键:您必须更改通过数组的方式

您应该使用foreach循环,而不是使用
while
循环并通过索引访问数组元素,因为foreach循环只能从数组中获取元素:

$array = array_values($array);
谢谢塔图

对于lulz,我将与您分享我在等待合理答案时使用的以下白痴黑客:

foreach ($array as $key => $value) {
    // $key contains the index of the current element
    // $value contains the value of the current element
}

成功了。让我觉得浑身脏兮兮的,但它起了作用。

+1对你来说,因为我肯定会在其他地方使用这些知识。但是,这张支票必须交给塔图,因为他打了靶子。谢谢你,帕斯卡。@安德鲁:不客气:-);;是的,我知道我没有真正回答这个问题,但我认为这无论如何都是有用的(我总是使用foreach循环数组元素);;当我看到另一个关于
数组\u值的答案时,我没有把它放在我的答案中。我很感谢你花时间回答,我真的这么做了。我的脚还在湿透,很明显,我正处于学习编程的“我有一个非常棒的锤子”阶段。因此,再次感谢您为更合适的代码设计所做的扩展和帮助。
foreach ($array as $key => $value) {
    // $key contains the index of the current element
    // $value contains the value of the current element
}
$badArray = array_diff($allData, $myData);

$string = implode(",",$badArray);

$dump = explode(",",$string);

$goodArray = $dump;