PHP数组订单

1585364631
2022-03-15 / 0 评论 / 148 阅读 / 正在检测是否收录...

PHP数组订单

PHP数组订单
订单
物品价格地方数量小计
主板379广东31137
显卡799上海21598
硬盘589北京52945
总计:5680
<!DOCTYPE html>
<meta charset="utf-8" />
<head>
    <style>
        table{
            text-align: center;
        }
         td{
            text-align: center;
            width: 200px;
        }
    </style>
    
    <title>PHP数组订单</title>
    <?php
        $title = array('物品','价格','地方','数量','小计');
        $goods = array(
            array('name'=>'主板','price'=>'379','producing'=>'广东','num'=>3),
            array('name'=>'显卡','price'=>'799','producing'=>'上海','num'=>2),
            array('name'=>'硬盘','price'=>'589','producing'=>'北京','num'=>5),
        );
        
        echo "<table border='1'><tr>
            <th colspan='5'>订单</th>
        </tr><tr>";
        foreach($title as $i => $ii){
            echo "<td>$ii</td>";
        }
        echo "</tr>";
        
        $sum_price = 0;
        
        foreach($goods as $i => $ii){
            echo "<tr>";
            foreach($ii as $j => $k){
                echo "<td>$k</td>";
                if($k == end($ii)) {
                    $small_price = $ii['price'] * $ii['num'];
                    $sum_price+=($small_price);
                    echo "<td>$small_price</td>";
                }
            }
            echo "</tr>";
        }
        echo "<tr><td colspan='5'>总计:$sum_price</td></tr></table>";
?>
</head>
</html>
0

评论 (0)

取消