1
echo $verified == 0?'Unverified':$verified == 2?'Shortlisted':'Verified'

Expected output when $verified = 0 is Unverified but it actually echo Shortlisted. After few tries, I did:

echo $verified == 0?'Unverified':($verified == 2?'Shortlisted':'Verified')

And it worked! I was just curious how exactly this is executing if anyone knows. I tried this in C language the result was Unverified that's why I'm especially tagging PHP.

This might sound an improper question for community but I wasn't able to find any article regarding this.

  • 2
    This should answer your question: [Ternary operator left associativity](https://stackoverflow.com/questions/20559150/ternary-operator-left-associativity). In PHP it has an associativity different from every other language. Anyway I upvoted your question because it made me learn something new. – Roberto Caboni Jun 19 '20 at 18:47

0 Answers0