php - Ternary operator and string concatenation quirk? -


hi want know why code yields (at least me) incorrect result.

well, i'm in fault here

$description = 'paper: ' . ($papertype == 'bond') ? 'bond' : 'other'; 

i guessing if papertype equals 'bond' description 'paper: bond' , if papertype not equals 'bond' description 'paper: other'.

but when run code results description either 'bond' or 'other' , left me wondering string 'paper: ' went???

$description = 'paper: ' . ($papertype == 'bond' ? 'bond' : 'other'); 

try adding parentheses string concatenated string in right order.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -