2

Is my return missing something?

return $var === 'apple' ? 'A' : $var === 'banana' ? 'B' : 'C';

There is only one issue is when $var is ='apple' is doesn't return A it returns B

I can definitely see the $var printing apple So why not returning A

For me the statement is correct anyone have any idea?

Juliano Vargas
  • 284
  • 2
  • 19

1 Answers1

2

You need to use () in second condition like below:

return $var === 'apple' ? 'A' : ($var === 'banana' ? 'B' : 'C');

Output:-

https://3v4l.org/tIFGH

https://3v4l.org/rtaAE

https://3v4l.org/ZGUQW

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98