2

次のコードを持つPHPテンプレートファイルがあります。

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

私がやりたいのは、このようなものを追加するとif the start_price == 0display_amountが表示されるはず0です。

現在、display_amount_ _-start_price0

何か助けはありますか?

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 に答える