I am working on a l'il CGI script that needs to print times translated from epoch. When I wrote the bit that converts 24 hour time to 12hour time, I got some weird behavior.
The problem code would label everything as am. I'm not sure why.
This didn't work:
$hour > 11 ? $xm = "pm" : $xm = "am";
These did:
if ($hour > 11) {$xm = "pm"} else {$xm = "am"};
$hour > 11 ? ($xm = "pm") : ($xm = "am");
So how do I know when to use parentheses on ?: clauses? Is it better to always use them? I am quite confused.
In reply to Weird ?: behavior by TGI
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |