PHP - Concatenate if statement?

前端 未结 4 894
暗喜
暗喜 2020-12-10 07:06

I want to concatenate in the middle of an echo to write an if statement, is this possible? Here is what I have.

echo \"
  • 4条回答
    •  死守一世寂寞
      2020-12-10 07:47

      Instead of messy inline concatenations, might I suggest getting cozy with printf()?

      $format = '
    • Home
    • '; printf($format, ($_GET['p'] == 'home') ? 'active' : '');

    提交回复
    热议问题