实例
<?php // header include __DIR__ . "/component/header.php"; //build html template by php echo '<ol>'; foreach ( $cates as $cate ): // echo title echo '<h2>' . $cate['name'] . '</h2>'; //echo list foreach ( $foods as $food ): //find same id if ( $cate['cate_id'] === $food['cate_id'] ) { echo '<li><a href="detail.php?foods_id=' . $food['foods_id'] . '">' . $food['name'] . '</a></li>'; } endforeach; endforeach; echo '</ol>'; // footer include __DIR__ . '/component/footer.php';
运行实例 »
点击 "运行实例" 按钮查看在线实例
实例
<?php // 加载公共头部 include __DIR__ . '/component/header.php'; //get the cate_id to show which pages $integerId = intval( $_GET['cate_id'] ); echo '<ol>'; foreach ( $cates as $cate ): if ( $integerId == $cate['cate_id'] ) { echo '<h2>' . $cate['name'] . '</h2>'; foreach ( $foods as $food ): if ( $cate['cate_id'] == $food['cate_id'] ) { echo '<li><a href="detail.php?foods_id=' . $food['foods_id'] . '">' . $food['name'] . '</a></li>'; } endforeach; } endforeach; echo '</ol>'; // 加载公共底部 include __DIR__ . '/component/footer.php';
运行实例 »
点击 "运行实例" 按钮查看在线实例
实例
<?php // 加载公共头部 include __DIR__ . '/component/header.php'; $integerId = intval( $_GET['foods_id'] ); foreach ( $foods as $food ): if ( $integerId == $food['foods_id'] ) { echo $food['name'] . '<br>'; echo $food['detail']; } endforeach; // 加载公共底部 include __DIR__ . '/component/footer.php';
运行实例 »
点击 "运行实例" 按钮查看在线实例
作業上傳到github中。
https://github.com/beebb0128/php.cn