-1

I have:

 echo '<ul id="my-list" class="'.(true) ? 'classA' : 'classB'.'">';

But the HTML is not being output, only the text classA is being outputted to the page.

Where am I going wrong?

panthro
  • 22,779
  • 66
  • 183
  • 324

1 Answers1

1

Try to use additionnal parenthesis :

echo '<ul id="my-list" class="'.((true) ? 'classA' : 'classB').'">';

Because the concatenation operator( like the majority of operators in php) will cast the object to its right to the same type as the object on its left .

Damian Nikodem
  • 1,324
  • 10
  • 26
blue112
  • 52,634
  • 3
  • 45
  • 54