You are here: Re: Shortened "If - Then - Else"? « PHP Programming Language « IT news, forums, messages
Re: Shortened "If - Then - Else"?

Posted by Andy Hassall on 11/13/73 11:20

On 4 Jul 2005 04:47:10 -0700, "binderup@gmail.com" <binderup@gmail.com> wrote:

>Why would people use the shortened version?

The ternary operator is not equivalent to an if statement; it is an
expression. So you can also avoid writing code to assign to temporaries.

$x = true;

if ($x)
{
$str = 'true';
}
else
{
$str = 'false';
}

print $str;

# versus

print $x ? 'true' : 'false';

>I find it much harder to read,

Depends on the circumstance.

It's only really useful for trivial conditions.

--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool

 

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

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