1 ? $x=1 : $x=0
really means
(1 ? $x=1 : $x)=0
which is then the same as
($x=1)=0
which is why $x becomes 0.
You can use assignments within ? :, you just need to parenthesize them
1 ? $x=1 : ($x=0)
In reply to Re^7: Short form (ternary) if else
by wrog
in thread Short form (ternary) if else
by gg48gg
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |