2

我有一个 PHP 模板文件,其中包含以下代码:

<td class="redfont">
    <strong><?=$fees->display_amount($item_details['start_price'], $item_details['currency']); ?></strong>

我想做的是添加这样的东西if the start_price == 0 然后display_amount应该显示0

现在display_amount显示-_ start_price_0

有什么帮助吗?

4

4 回答 4

2

你可以这样做。

<td class="redfont"><strong><?= ($item_details['start_price'] == 0) ? 0 : $fees->display_amount($item_details['start_price'], $item_details['currency']); ?></strong>
于 2012-04-26T05:58:05.047 回答
1
<td class="redfont">
<strong>
    <?php 
        if ($item_details['start_price'] == 0)
            "0";
        else
            $fees->display_amount($item_details['start_price'], $item_details['currency']); 
    ?>
</strong>
</td>
于 2012-04-26T05:57:02.637 回答
1
<td class="redfont"><strong><?= $item_details['start_price'] == 0 ? "0" : $fees->display_amount($item_details['start_price'], $item_details['currency']) ?></strong>
于 2012-04-26T05:57:53.283 回答
1
<?php
YourClass {

   public function display_amount($startPrice, $currency) {
      if ($startPrice == 0) {
         return "0";
      } else {
         //do other things code here
         //return your_result
      }
   }
}
?>

<td class="redfont"><strong><?=$fees->display_amount($item_details['start_price'], $item_details['currency']); ?></strong>

您可以将控制权放在您的函数中或在 html 中返回结果时。我更喜欢将控制权放在函数中

于 2012-04-26T06:02:31.903 回答