3 ms·
I have not touched PHP in the last 10 years but if memory serves it also has the ternary operator. Ok, lets try it: $ php -a Interactive mode enabled
by scardine 7y ago
I have not touched PHP in the last 10 years but if memory serves it also has the ternary operator. Ok, lets try it:
$ php -a
Interactive mode enabled
php > echo 1 == 1 ? "foo" : "bar";
foo
php > echo 1 == 2 ? "foo" : "bar";
bar
Looks like javascript has it too:
1 == 1 ? "foo" : "bar"
"foo"
1 == 2 ? "foo" : "bar"
"bar"
- amenghra 7y agoBe careful, php’s ternary operator precedence is different from (most) other languages’ (consult binding direction). The use of parenthesis is highly encouraged...