<?php
//case 8 显示订单信息
header("Content-type:text/html;charset=utf-8");
//多维数组
$goods = array(
array('name'=>'主板','price'=>'779','producing'=>'广东','num'=>4),
array('name'=>'显卡','price'=>'1299','producing'=>'深圳','num'=>2),
array('name'=>'硬盘','price'=>'689','producing'=>'金三角','num'=>5)
);
//合计金额
$total = 0;
$str = "<table border='1' cellspacing='0' style='text-align: center;width: 30%;'>";
$str .= "<tr><th>商品名称</th><th>价格(元)</th><th>产地</th><th>数量(件)</th><th>总价(元)</th>";
//数组一维
foreach($goods as $values)
{
$str .= "<tr>";
//数组二维
foreach($values as $val)
{
$str .= "<td>{$val}</td>";
}
//单行合计
$sum = $values['price'] * $values['num'];
$str .= "<td>{$sum}</td>";
$str .= "</tr>";
//总额合计
$total += $sum;
}
$str .= "<tr><td colspan='5' align='right'>小计:{$total}元</td></tr>";
$str .= "</table>";
echo $str;