实例
<?php $title='表格制作'; $product_price='产品价格表'; $model=[ 'macbook'=>['256','16g','i5','13.3','银色'], 'xiaomi'=>['128','8g','i3','15.3','银色'], 'lenveo'=>['512','32g','i7','14.3','银色'] ]; ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <link rel="stylesheet" href="static/style.css"> <title><?php echo $title;?></title> </head> <body> <table> <caption><?php echo $product_price;?></caption> <thead> <tr> <th>型号</th> <th>硬盘</th> <th>内存</th> <th>cpu</th> <th>尺寸</th> <th>颜色</th> </tr> </thead> <tbody> <?php foreach ($model as $k=>$v){ ?> <tr> <td ><?php echo $k?></td> <?php foreach ($v as $v1){ ?> <td ><?php echo $v1?></td> <?php } ?> </tr> <?php } ?> </tbody> <tfoot> <tr> <td>备注:</td> <td colspan="5">颜色以当天发货为准</td> </tr> </tfoot> </table> </body> </html>
运行实例 »
点击 "运行实例" 按钮查看在线实例
php数组混编操作主要就是括号这块的使用,容易遇到坑。然后就是两个foreach的使用,理解循环的顺序。