Posted by Andy Hassall on 11/12/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
[Back to original message]
|