Reply to Re: Assigning variables in if's

Your name:

Reply:


Posted by jodleren on 11/29/07 06:21

On Nov 28, 12:35 pm, Captain Paralytic <paul_laut...@yahoo.com> wrote:
> 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.- Hide quoted text -
>
> - Show quoted text -

If found, that it does not work, so I ended up using this

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

and probably I'll change it to return 0 as no error.

WBR
Sonnich

[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

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