Reply to Re: Assigning variables in if's

Your name:

Reply:


Posted by Captain Paralytic on 11/28/07 10:35

On 28 Nov, 09:24, jodleren <sonn...@hot.ee> wrote:
> Hi!
>
> In while (false !== ($file = readdir($handle)))
>
> what happens?
> The $file gets assigned, and the value of that is compared with false?
> The assignment is being compared with false
>
> Say, I want to return true or an error code. Can I do;
>
> if($err = somefunc())
> echo "ok"
> else
> echo "error: $err";
>
> WBR
> Sonnich

if($err = somefunc())
echo "ok"
else
echo "error: $err";

may work.

An assignment "returns" the value that was assigned. This is why you
can do:

$a = $b = $c = 5;

and all 3 variables will have the value 5.

In your "if" comparison, any non-empty or non-zero value in the
brackets will be taken to be true.

So, if somefunc() returns 0 or nothing for a good result, then your
statement will do what you want.

[Back to original 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

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