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];
.
.
.
.
}
}
}

It's my code and when I use it :

> 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

I use isset() to check my data. if all is set why produces an error?

in this code we have 2 $_POST and they are checked in line 1 and other data is array and I check it 100 time and I do not see where is error. Please see lines 8 and 9. They do not have error. Although the structure is similar to other lines.Why?

naser
  • 171
  • 2
  • 13
  • undefined index:[...] the tree dots is where the error says wich index is undifine – Emilio Gort Sep 08 '13 at 02:10
  • Without looking at it ... are all those $a_dino[$_POST['xyz']] and alike set? If NOT, you have to check them with isset() also. Show us the line of code where the error occurs. – djot Sep 08 '13 at 02:10
  • ok edited and I add all error. and now? – naser Sep 08 '13 at 02:41
  • Well, it tells you loud and clear, the problems is where u use number 4 as index... – Itay Moav -Malimovka Sep 08 '13 at 11:37
  • ya, I know. `$_POST['dino_box'] = 4` and I use it in all line but in line 8 & 9 we don't have an error. why? I sure that all data is set ... – naser Sep 08 '13 at 15:20

1 Answers1

4

When u do isset($r['t']['b']['v']);

It assumes $r['t']['b'] already exists, and checks only the ['v'].
If those ['t'] or ['b'] are none existent PHP will emit a warning, even if it is inside isset

So to check such multiple dim array is actually:

if(isset($r['t'])&&isset($r['t']['b'])&&isset($r['t']['b']['v'])){...
Itay Moav -Malimovka
  • 52,579
  • 61
  • 190
  • 278
  • ty for answer. but all is set.I check it 100 time. they are array and data form database. do you need to see array? – naser Sep 08 '13 at 02:45
  • `isset` checks if the variable is defined. If i check something like `var_dump( isset($undefinedVar[1][2][3]) );` it will return false not the warnings. Can you provide some clear example that explains your point "It assumes $r['t']['b'] already exists, and checks only the ['v']. If those ['t'] or ['b'] are none existent PHP will emit a warning, even if it is inside isset". – Konsole Sep 08 '13 at 03:43