<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>foreach语句的应用</title>

</head>
<style type="text/css">
<!--
.STYLE1 {font-size: 13px;
       	color: #FF0000;
	font-weight: bold;
}
.STYLE2 {font-size: 13px;
      

}
-->
</style>
<body>
<table width="580" height="180" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td><img src="images/bg.jpg" width="580" height="150"></td>
  </tr>
  <tr>
    <td height="30" align="left" bgcolor="#EEEFE9" class="STYLE1">&nbsp;&nbsp;购物车商品信息展示</td>
  </tr>
</table>
<?php
$name = array("1"=>"钢笔","2"=>"衬衫","3"=>"手机","4"=>"电脑");
$price = array("1"=>"108元","2"=>"88元","3"=>"666元","4"=>"6666元");
$counts = array("1"=>1,"2"=>1,"3"=>2,"4"=>1);
echo '<table width="580" border="1" cellpadding="1" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#FF0000">
          <tr>
            <td width="145" align="center" bgcolor="#FFFFFF"  class="STYLE1">商品名称</td>
            <td width="145" align="center" bgcolor="#FFFFFF"  class="STYLE1">价 格</td>
            <td width="145" align="center" bgcolor="#FFFFFF"  class="STYLE1">数量</td>
            <td width="145" align="center" bgcolor="#FFFFFF"  class="STYLE1">金额</td>
         
 </tr>';
foreach($name as $key=>$value){  //以book数组做循环，输出键和值
     echo '<tr>
            <td height="25" align="center" bgcolor="#FFFFFF" class="STYLE2">'.$value.'</td>
            <td align="center" bgcolor="#FFFFFF" class="STYLE2">'.$price[$key].'</td>    
            <td align="center" bgcolor="#FFFFFF" class="STYLE2">'.$counts[$key].'</td>
            <td align="center" bgcolor="#FFFFFF" class="STYLE2">'.$counts[$key]*$price[$key].'</td>
</tr>';
}
echo '</table>';
?></body>
</html>
