in reply to Weird ?: behavior
The ternary operator (?:) has a higher precendence than =. That's why it's getting parsed that way.$hour > 11 ? ($xm = 'pm') : $xm = 'am';
Anyway, IMO, the best way to write that would be:
No precendence problems, and it's clearer, to me. I like using ternary operators for assignment, not for executing arbitrary code. It's just a matter of personal preference, really, but in certain cases it'll keep you out of trouble. Like this one. :)$xm = $hour > 11 ? "pm" : "am";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Re: Weird ?: behavior
by turnstep (Parson) on Aug 08, 2000 at 23:02 UTC | |
|
RE: Re: Weird ?: behavior
by tye (Sage) on Aug 08, 2000 at 23:18 UTC |