我有每月和每年费用的价格表,但是我需要一个价格表,供免费使用。如果我将价格设置为零,则会收到错误消息,原因是代码无法读取零价格。下面的代码段。谢谢
<?php foreach ($Packages->getDataAs("Package") as $p): ?>
<div class="price">
<div class="price-content">
<div class="main-price">
<h1><?= format_price($p->get("monthly_price")) ?></h1>
<p><?= htmlchars($Settings->get("data.currency")) ?>/<?= __("per month") ?></p>
</div>
<p class="special-discount">
<?php
$total = 12 * $p->get("monthly_price");
$dif = $total - $p->get("annual_price");
$save = $dif * 100 / $total;
if ($save > 0) {
echo __("Save %s when paid annualy", format_price($dif) . " " . htmlchars($Settings->get("data.currency")));
}
?>
</p>
答案 0 :(得分:0)
添加此内容即可解决您的问题
$total = 12 * $p->get("monthly_price");
$dif = $total - $p->get("annual_price");
if($total > 0) //Omits Divide by zero exception
$save = $dif * 100 / $total;
else
$save = 0;