+ 4

Why php displays here wrong result?

https://code.sololearn.com/wgAEnj16uL1L/?ref=app

31st Jan 2019, 9:56 AM
Dejan Dozet
Dejan Dozet - avatar
4 Respuestas
+ 4
KrOW thanks, so left side associative is in php, does that mean that in JavaScript is different? Surely it is different, because result there is 1 as it should be - right side or? For me this is confusing beyond understanding. I have to admit that Ive had similar situations in my php code that I have to resolve by using explicit parenthesis.
31st Jan 2019, 12:11 PM
Dejan Dozet
Dejan Dozet - avatar
+ 2
Im not sure but i think that before is valued the first ternary operator which result is used in the second... In practice: true ? 1 : false? 2:3 its like ((true ? 1 : false)? 2:3) then : ((1)?2:3 == 2
31st Jan 2019, 10:46 AM
KrOW
KrOW - avatar
+ 1
Just now i readed than ternary operator is left-side associative then, its like i said
31st Jan 2019, 10:56 AM
KrOW
KrOW - avatar
+ 1
de do Yes... Php use left-to-right associativity for ternary, js use right-to left makin previous expression valued like: (true? 1:(false? 2:3))
31st Jan 2019, 1:39 PM
KrOW
KrOW - avatar