index.php
实例
<?php include __DIR__ . '/inc/header.php'; foreach ($cate as $cate) { echo "<h2>{$cate['alias']}</h2>"; echo '<ol>'; foreach ($goods as $good) { if ($cate['cate_id'] === $good['cate_id']) { echo "<li><a href='detail.php?goods_id=" .$good['goods_id']. "'>{$good['name']}</a></li>"; } } echo '</ol>'; } include __DIR__ . '/inc/footer.php';
运行实例 »
点击 "运行实例" 按钮查看在线实例
header.php
实例
<?php $goods = [ [ 'goods_id'=>1, 'name'=>'华为手机', 'image'=>'1.jpg', 'detail'=>'华为一出,天下无敌… ', 'cate_id'=>1 ], [ 'goods_id'=>2, 'name'=>'小米手机', 'image'=>'2.jpg', 'detail'=>'发烧友最爱', 'cate_id'=>1 ], [ 'goods_id'=>3, 'name'=>'联想电脑', 'image'=>'3.jpg', 'detail'=>'经典***…', 'cate_id'=>2 ], [ 'goods_id'=>4, 'name'=>'惠普电脑', 'image'=>'4.jpg', 'detail'=>'******…', 'cate_id'=>2 ], ]; $cate = [ ['cate_id'=>1, 'name'=>'sj', 'alias'=>'手机'], ['cate_id'=>2, 'name'=>'dn', 'alias'=>'电脑'], ]; $system = [ 'sys_id'=>1, 'title'=>'网上商城', 'desc'=>'收集全网最新最全的资源', 'key'=>'手机,电脑', 'copy'=>'php中文网' ]; ?> <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <link rel="stylesheet" href="staic/css/css.css"> <meta name="description" content="<?php echo $system['desc'] ?>"> <meta name="keywords" content="<?php echo $system['key'] ?>"> <title><?php echo $system['title'] ?></title> </head> <body> <!--头部导航--> <div class="header"> <ul class="nav"> <li><a href="index.php">首页</a></li> <?php foreach ($cate as $cates) : ?> <li><a href="list.php?cate_id=<?php echo $cates['cate_id']; ?>"><?php echo $cates['alias'] ?></a></li> <?php endforeach; ?> </ul> </div>
运行实例 »
点击 "运行实例" 按钮查看在线实例
footer.php
实例
<!--底部版权--> <div class="footer"> <p class="copyright"><?php echo $system['copy'] ?> © 版权所有</p> </div> </body> </html>
运行实例 »
点击 "运行实例" 按钮查看在线实例
list.php
实例
<?php include __DIR__ . '/inc/header.php'; $cate_id = $_GET['cate_id']; $cate_id = intval($cate_id); foreach ($cate as $cate) { if ($cate['cate_id'] === $cate_id) { echo "<h2>{$cate['alias']}</h2>"; echo '<ol>'; foreach ($goods as $goods) { if ($cate['cate_id'] == $goods['cate_id']) { echo "<li><a href='detail.php?goods_id=" .$goods['goods_id']. "'>{$goods['name']}</a></li>"; } } echo '</ol>'; break; }; } include __DIR__ . '/inc/footer.php';
运行实例 »
点击 "运行实例" 按钮查看在线实例
detail.php
实例
<?php // 加载公共头部 include __DIR__ . '/inc/header.php'; $goods_id = intval($_GET['goods_id']); foreach ($goods as $good) { if ($good['goods_id'] === $goods_id) { echo "<h3>{$good['name']}</h3>"; echo '<img src="/staic/images/'.$good['image'].'" alt="" width="300">'; echo "<p style='text-indent: 2em'>{$good['detail']}</p>"; } }; include __DIR__ . '/inc/footer.php';
运行实例 »
点击 "运行实例" 按钮查看在线实例