I am having trouble with a PHP foreach loop....I know how they work, I think I'm getting unexpected results. A bug perhaps? Am I missing something?
if(is_array($array)){
foreach ($array as $k => $v){
echo "<b>#$k</b><br />";
foreach ($v as $kk => $vv){
foreach ($vv as $kkk => $vvv){
if($kkk == "name"){echo "$kkk = NAME | ";}
if($kkk == "comment"){echo "$kkk = COMMENT | ";}
echo "<br />";
}
}
}
}else{
echo "Arguement is not a proper code array.";
}
The problem is that both of these lines are returning true and echoing the $kkk = xxx statement, but clearly you can see that only one of these lines should ever return true at a time.
if($kkk == "name"){echo "$kkk = NAME | ";}
if($kkk == "comment"){echo "$kkk = COMMENT | ";}
Here is the output I am getting, data is from a fiel upload:
#007 - Tomorrow Never Dies#slus-00975
name = NAME |
0 = NAME | 0 = COMMENT |
name = NAME |
0 = NAME | 0 = COMMENT |
name = NAME |
0 = NAME | 0 = COMMENT |
name = NAME |
0 = NAME | 0 = COMMENT |
#007 - Tomorrow Never Dies#slps-00000
name = NAME |
0 = NAME | 0 = COMMENT |
name = NAME |
0 = NAME | 0 = COMMENT |
I don't understand how this is happening, I would expect this if I was only using one '=' sign in the IF statement or something, but this has got me scratching my head.
Thanks!