简体   繁体   中英

How to put an if statement inside a variable?

$galleryDetails .='
        <div class="col-md-3 product-left">

  <p class = "tb">Total Bid: if($rowSelectCountTotal > 0){$rowSelectCountTotal}else {0}</p>
</div>

Above is my code , i try to put if else statement inside the variable but cant work,how can i put the if else inside the variable?

Simply do:

$galleryDetails .='
        <div class="col-md-3 product-left">

  <p class = "tb">Total Bid: '.(($rowSelectCountTotal > 0) ? $rowSelectCountTotal : 0)'.</p>
</div>

This is called Shorthand if/else , and allows you to achieve what you're trying to do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM