我无法理解这种行为,我在循环中有以下代码来识别数组中是否有“data”索引。如果它不存在,我尝试识别前一个数组值,下一个数组值和当前数组值,但我不能理解的是,前一个数组在先前正确显示时显示未定义的偏移量错误。这样:
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
但是...... finalstring[11][72]
已正确显示
我缺少什么?
答案 0 :(得分:0)
当前数组名称为$finalstrings
(s
},您尝试使用$finalstring
(不使用s
)。