When I want clarity, or when I specifically want to avoid an undefined value, I tend to use the trinary operator:
$bool = $x ? 1 : 0;
When I want shortness I tend to use !!$x.
When I'm comparing truthness of two expressions, I factor out one of the !s:
if (!$x == !$y) { ... }
Hugo
In reply to Re: Converting to boolean
by hv
in thread Converting to boolean
by dragonchild
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |