You are here: Re: if...else - in which order « PHP Programming Language « IT news, forums, messages
Re: if...else - in which order

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация