简体   繁体   中英

Styling output in ternary operator

how to put color the in output of ternary operator.

I would like to do if false it should be black if true it should be red

this is my code:

'<td>' .($totalStocks < $minimumStockLevel ? 'true': 'false'). '</td>' .

You need some CSS, and then add an appropriate class to your data:

<style>
  .redCell {color:red;}
  .blackCell {color:black;}
</style>

Then your code becomes:

'<td class="'.($totalStocks < $minimumStockLevel ? 'redCell': 'blackCell').'">' .$someValue. '</td>' .

This should generate something like this:

<td class="redCell">someValue</td>

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