|
Posted by Jason F. on 05/10/05 22:54
juglesh wrote:
> "$string = isset($xyz) ? $xyz : "something else";"
>
>
> Hello, someone gave code like this in another thread. I understand (by
>
> inference) what it does, but have not found any documentation on this
> type of syntax.
That's the ternary operator, which you'll find in a lot of languages
besides just PHP.
The above example is exactly equivalent to:
if (isset($xyz)) {
$string = $xyz;
} else {
$string = "something else";
}
In the interest of *easily readable code* I would recommend that you try
*NOT* to use the ternary much just to appear clever. Sure, it's more
compact, but it takes a couple extra seconds to figure out what's going
on VS an if/else.
Navigation:
[Reply to this message]
|