关键词搜索

源码搜索 ×
×

PHP笔记-订货单例子

发布2021-12-27浏览1318次

详情内容

程序运行截图如下:

源码如下:

  1. <?php
  2. $goods = [
  3. ["name" => "主板", "price" => 979, "producing" => "广州", "num" => 8],
  4. ["name" => "显卡", "price" => 1599, "producing" => "上海", "num" => 19],
  5. ["name" => "硬盘", "price" => 579, "producing" => "广州", "num" => 21],
  6. ["name" => "CPU", "price" => 2999, "producing" => "北京", "num" => 31],
  7. ];
  8. ?>
  9. <title>商品订货单</title>
  10. <table border="1" cellpadding="1" cellspacing="1">
  11. <tr>
  12. <td colspan="5">商品订货单</td>
  13. </tr>
  14. <tr>
  15. <td>商品名称</td>
  16. <td>价格(元)</td>
  17. <td>产地</td>
  18. <td>数量(件)</td>
  19. <td>总价(元)</td>
  20. </tr>
  21. <?php
  22. $total = 0;
  23. foreach ($goods as $values){
  24. $str = "<tr>";
  25. foreach ($values as $v){
  26. $str .= "<td>" . $v . "</td>";
  27. }
  28. $sum = $values["price"] * $values["num"];
  29. $str .= "<td>" . $sum . "</td>";
  30. $str .= "</tr>";
  31. echo $str;
  32. $total += $sum;
  33. }
  34. $str = "<tr><td colspan='5'>小计: " . $total . "元</td> </tr>";
  35. echo $str;
  36. ?>
  37. </table>

 

相关技术文章

点击QQ咨询
开通会员
返回顶部
×
微信扫码支付
微信扫码支付
确定支付下载
请使用微信描二维码支付
×

提示信息

×

选择支付方式

  • 微信支付
  • 支付宝付款
确定支付下载