Title1

Title2

Title3

5-2 foreach 範例

一、5_7.php

<?php
echo "<meta charset='utf-8'>";

$nav=array("首頁","聯絡我們","關於我們");

foreach ($nav as $title){
  echo $title."<br>";
}

二、5_8.php,您可以將這個帶入 nav.php

<?php
echo "<meta charset='utf-8'>\n";

/*
<li><a href='index.php'>首頁</a></li>
<li><a href='about_us.php'>關於我們</a></li>
<li><a href='contact.php'>聯絡我們</a></li>
 */

$nav=array("index.php" => "首頁" ,"about_us.php" => "關於我們" , "contact.php" => "聯絡我們");
$nav_li="";
foreach ($nav as $href => $title){
  $nav_li .= "<li><a href='{$href}'>{$title}</a></li>\n";
}
// \n為換行
echo $nav_li;