0
if(isset($_POST['dino_c']) AND isset($_POST['dino_box']) AND isset($dino_recruit[$a_dino[$_POST['dino_c']][1]][$a_dino[$_POST['dino_c']][3]][$_POST['dino_box']])){
if(....){
if(($pop>(0-1+$dino_recruit[$a_dino[$_POST['dino_c']][1]][$a_dino[$_POST['dino_c']][3]][$_POST['dino_box']][4])) AND ($resource[0]>(0-1+$dino_recruit[$a_dino[$_POST['dino_c']][1]][$a_dino[$_POST['dino_c']][3]][$a_dino[$_POST['dino_box']]][5] -1)) AND ($resource[1]>(0-1+$dino_recruit[$a_dino[$_POST['dino_c']][1]][$a_dino[$_POST['dino_c']][3]][$a_dino[$_POST['dino_box']]][6] -1)) AND ($resource[2]>(0-1+$dino_recruit[$a_dino[$_POST['dino_c']][1]][$a_dino[$_POST['dino_c']][3]][$a_dino[$_POST['dino_box']]][7] -1))){
.
.
.
.
$pop = $pop - $dino_recruit[$a_dino[$_POST['dino_c']][1]][$a_dino[$_POST['dino_c']][3]][$_POST['dino_box']][4];
$pop_consum = $pop_consum + $dino_recruit[$a_dino[$_POST['dino_c']][1]][$a_dino[$_POST['dino_c']][3]][$_POST['dino_box']][4];
$resource[0] = 0 + $dino_recruit[$a_dino[$_POST['dino_c']][1]][$a_dino[$_POST['dino_c']][3]][$a_dino[$_POST['dino_box']]][5];
$resource[1] = 0 + $dino_recruit[$a_dino[$_POST['dino_c']][1]][$a_dino[$_POST['dino_c']][3]][$a_dino[$_POST['dino_box']]][6];
$resource[2] = 0 + $dino_recruit[$a_dino[$_POST['dino_c']][1]][$a_dino[$_POST['dino_c']][3]][$a_dino[$_POST['dino_box']]][7];
$dino_add[$a_dino[$_POST['dino_c']][1]-1] = 0 + $dino_recruit[$a_dino[$_POST['dino_c']][1]][$a_dino[$_POST['dino_c']][3]][$a_dino[$_POST['dino_box']]][0];
.
.
.
.
}
}
}

这是我的代码,当我使用它时:

> undefined index:4 in .... ajax.php on line 672  => here line 3
> undefined index: in .... ajax.php on line 672  => here line 3
> undefined index:4 in .... ajax.php on line 672  => here line 3
> undefined index: in .... ajax.php on line 672  => here line 3
> undefined index:4 in .... ajax.php on line 672  => here line 3
> undefined index: in .... ajax.php on line 672  => here line 3
> undefined index:4 in .... ajax.php on line 679  => here line 10
> undefined index: in .... ajax.php on line 679  => here line 10
....
> undefined index:4 in .... ajax.php on line 682  => here line 13
> undefined index: in .... ajax.php on line 682  => here line 13

我使用 isset() 检查我的数据。如果一切都设置好了,为什么会产生错误?

在这段代码中,我们有 2 个 $_POST,它们在第 1 行中被检查,其他数据是数组,我检查了 100 次,但看不到哪里有错误。请参阅第 8 行和第 9 行。它们没有错误。虽然结构与其他线路相似。为什么?

4

1 回答 1

4

当你做isset($r['t']['b']['v']);

它假定$r['t']['b']已经存在,并且只检查['v'].
如果这些['t']['b']不存在 PHP 将发出警告,即使它在里面isset

所以要检查这样的多个暗淡数组实际上是:

if(isset($r['t'])&&isset($r['t']['b'])&&isset($r['t']['b']['v'])){...
于 2013-09-08T02:10:51.793 回答