我有一个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
任何帮助?
答案 0 :(得分:2)
<td class="redfont"><strong><?= ($item_details['start_price'] == 0) ? 0 : $fees->display_amount($item_details['start_price'], $item_details['currency']); ?></strong>
答案 1 :(得分: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>
答案 2 :(得分:1)
<td class="redfont"><strong><?= $item_details['start_price'] == 0 ? "0" : $fees->display_amount($item_details['start_price'], $item_details['currency']) ?></strong>
答案 3 :(得分: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中返回结果时。我更喜欢把控制放在函数中