Posted by Erwin Moller on 11/01/06 12:08
Sonnich wrote:
> this is probably an old topic:
>
> if(a==1)
> if(b==2)
> echo "a is 1 and b is 2";
> else
> // what happens here?
> echo "a is 1 and b is not 2";
>
> The question is, where the else will react too. Usually it should be
> the last if.
>
> In general I put {} around just to be sure.
>
> BR
> Sonnich
Hi,
Use {} to note (to yourself and PHP) what you are doing.
The confusion you have is created by yourself. :-)
Try this:
if(a==1){
// a is 1
if(b==2){
// b is 2
echo "a is 1 and b is 2";
} else {
// b is not 2
echo "a is 1 and b is not 2";
} // end inner if-then-else
} // end outer if
Regards,
Erwin Moller
Navigation:
[Reply to this message]
|