PHP笔记-订货单例子

Posted IT1995

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP笔记-订货单例子相关的知识,希望对你有一定的参考价值。

程序运行截图如下:

源码如下:

<?php
    $goods = [
        ["name" => "主板", "price" => 979, "producing" => "广州", "num" => 8],
        ["name" => "显卡", "price" => 1599, "producing" => "上海", "num" => 19],
        ["name" => "硬盘", "price" => 579, "producing" => "广州", "num" => 21],
        ["name" => "CPU", "price" => 2999, "producing" => "北京", "num" => 31],
    ];
?>

<title>商品订货单</title>
<table border="1" cellpadding="1" cellspacing="1">
    <tr>
        <td colspan="5">商品订货单</td>
    </tr>
    <tr>
        <td>商品名称</td>
        <td>价格(元)</td>
        <td>产地</td>
        <td>数量(件)</td>
        <td>总价(元)</td>
    </tr>
    <?php
        $total = 0;
        foreach ($goods as $values)

            $str = "<tr>";
            foreach ($values as $v)


                $str .= "<td>" . $v . "</td>";
            
            $sum = $values["price"] * $values["num"];
            $str .= "<td>" . $sum . "</td>";
            $str .= "</tr>";
            echo $str;

            $total += $sum;
        

        $str = "<tr><td colspan='5'>小计: " . $total . "元</td> </tr>";
        echo $str;
    ?>
</table>

 

以上是关于PHP笔记-订货单例子的主要内容,如果未能解决你的问题,请参考以下文章

PHP笔记-用户登录例子

PHP笔记-用户登录例子

PHP笔记-平润年判断例子

PHP笔记-平润年判断例子

PHP-会员登录与注册例子解析-学习笔记

PHP笔记-学生成绩例子