PHP笔记-商品价格例子
Posted IT1995
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP笔记-商品价格例子相关的知识,希望对你有一定的参考价值。
程序运行截图如下:
源码如下:
<?php
const discount = 0.8;
$fruit1 = "橙子";
$fruit2 = "柚子";
$fruit3 = "橘子";
$fruit1Num = 1;
$fruit2Num = 2;
$fruit3Num = 3;
$fruit1Price = 6.88;
$fruit2Price = 3.99;
$fruit3Price = 3.28;
$fruit1Total = $fruit1Num * $fruit1Price;
$fruit2Total = $fruit2Num * $fruit2Price;
$fruit3Total = $fruit3Num * $fruit3Price;
$total = ($fruit1Total * $fruit2Total * $fruit3Total) * discount;
?>
<table border="1" cellpadding="1" cellspacing="1">
<tr>
<td>商品名称</td>
<td>购买数量(斤)</td>
<td>商品价格(元/斤)</td>
</tr>
<tr>
<td><?php echo $fruit1; ?></td>
<td><?php echo $fruit1Num; ?></td>
<td><?php echo $fruit1Price; ?></td>
</tr>
<tr>
<td><?php echo $fruit2; ?></td>
<td><?php echo $fruit2Num; ?></td>
<td><?php echo $fruit2Price; ?></td>
</tr>
<tr>
<td><?php echo $fruit3; ?></td>
<td><?php echo $fruit3Num; ?></td>
<td><?php echo $fruit3Price; ?></td>
</tr>
<tr>
<td colspan="3">
商品折扣: <span><?php echo discount; ?></span>
</td>
</tr>
<tr>
<td colspan="3">
打折后商品总价: <?php echo $total; ?>
</td>
</tr>
</table>
这里有几个要注意的地方:
①table中的border是那个表格的外边框,cellpadding指每个小格有多大,cellpadding指每个小格之间的距离;
②td中的colspan是指列的访问,上面的3就是,3个列合为1列。
以上是关于PHP笔记-商品价格例子的主要内容,如果未能解决你的问题,请参考以下文章
markdown 链接,片段,提醒,收集点作为重新访问WordPress插件开发期间的笔记#WordPress #Plugin #PHP #Refere