Reputation: 79
I am trying to use a ternary operator in a print statement like so:
print'<span class="mailbox-attachment-icon"><i class="fa fa-'. $extension == 'zip' ? 'yes' : 'no' .'"></i></span>';
It is breaking my page every time. I have attempted moving around '
's with no luck. Yes $extension
is defined.
How can I get this to work?
Upvotes: 0
Views: 199
Reputation: 25392
Your code is being evaluated left to right. You have to enclose that ternary clause in parentheses to ensure it is evaluated before being appended to the string.
print'<span class="mailbox-attachment-icon"><i class="fa fa-'. ($extension == 'zip' ? 'yes' : 'no') .'"></i></span>';
Upvotes: 2