Reputation: 63728
My ternary is returning an error. Am I forgetting some basic rule or quirk about using PHP ternaries with echos?
isset($tag) ?
echo '<a href="#">' . $tag['firstname'] . '</a>' : null;
The above ternary returns the following error:
Parse error: syntax error, unexpected T_ECHO in /classes/Photo.php on line 216
Upvotes: 1
Views: 1686
Reputation: 2180
Use print() instead of echo when you need to display text within an expression.
Upvotes: 2
Reputation: 2561
you should write like this:
echo (isset($tag) ? '<a href="#">' . $tag['firstname'] . '</a>' : '');
Upvotes: 17