Quote:
Originally Posted by plexiq
Code:
if(x){a}
elseif(y){b}
elseif(z){c}
else{d}
is equivalent to:
Code:
if(x){a}
else{
if(y){b}
else{
if(z){c}
else{d}
}
}
I'm not sure who's having a stroke here.
Code:
a ? a :
b ? b :
c ? c : d
Is equivalent to
Code:
if (a) {
a
}
elseif (b) {
b
}
elseif(c) {
c
}
else {
d
}
Code:
a ? ab ? ab : ac :
b ? b :
c ? c : d
Is equivalent to:
Code:
if (a) {
if (ab) {
ab
}
else {
ac
}
}
elseif (b) {
b
}
elseif(c) {
c
}
else {
d
}
I have coded quite a bit in ternaries (nested and non-nested). Two question marks in a row means nested if check. Two : in a row means exiting out of a nested block. Note, I am talking about JS. I know PHP's rules around ternaries aren't the same. I would need to surround any "nested" ternaries in () in order for them to be interpreted correctly. I'm guessing that is what's happening here.
Last edited by Craggoo; 12-11-2017 at 04:44 PM.