You are here: Re: Assigning variables in if's « PHP Programming Language « IT news, forums, messages
Re: Assigning variables in if's

Posted by Jerry Stuckle on 11/29/07 12:50

taps128 wrote:
> Toby A Inkster wrote:
>> jodleren wrote:
>>
>>> $err = somefunc();
>>> if($err===true)
>>> echo "ok"
>>> else
>>> echo "error: $err";
>>
>> echo (true === ($err = somefunc())) ? 'ok' : "error: $err";
>>
>> :-)
>>
> or more readable(to me) IMHO
> $err=foo();
> switch($err){
> case true: echo 'ok';break;
> case false: echo 'error: '.$err;
> }
>
> But of course thats just a matter of style.
>

More than a matter of style. If the function returns '1', your way will
print 'ok', while Toby's function will return the more correct 'error: 1'.



--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

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

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