先前回显数组上的未定义偏移错误


undefined offset error on previously echoed array?

我无法理解这种行为,我在循环中有以下代码来确定数组中是否有"数据"索引。如果它不存在,我会尝试识别以前的数组值、下一个数组值和当前数组值,但我不能理解的是,以前的数组在正确显示时会显示未定义的偏移错误。此:

if(array_key_exists('data', $finalstrings[$y][$p]))
{
    echo $counter." - finalstring[".$y."][".$p."]['data'] = DATA: ".$finalstrings[$y][$p]['data']."<br />";
    $counter++;
}
else
{
    echo "Doesn't exists DATA in finalstring[".$y."][".$p."]['data']</br />";
    $index = $p-1;
    $index2 = $p+1;
    echo "Index: ".$index." - Index2: ".$index2."<br />";
    echo "PREV: ".$finalstring[$y][$index]['data']."</br />";
    echo "NEXT: ".$finalstring[$y][$index2]['data']."</br />";
    print_r($finalstring[$y][$p]);
    echo "<br />";  
}

输出此:

478 - finalstring[11][72]['data'] = DATA: 554786242
Doesn't exists DATA in finalstring[11][73]['data']
Index: 72 - Index2: 74
Notice: Undefined offset: 11 in whatever/Info.php on line 134 PREV:
Notice: Undefined offset: 11 in whatever/Info.php on line 135 NEXT:
Notice: Undefined offset: 11 in whatever/Info.php on line 136
479 - finalstring[12][0]['data'] = DATA: 876547565

但CCD_ 1在以前已被正确显示
我缺少什么?

对应的数组名称为$finalstrings(带s),您可以尝试使用$finalstring(不带s)。