小编And*_*lis的帖子

得到PHP语法错误意外'foreach'(T_FOREACH)

我正在尝试制作一个foreach代码,自动为我的网站制作标题.我的想法是,当我添加更多页面时,我可以将它们添加到数组中,它将自动为我更新标题.通常我的foreach'工作,但我第一次遇到麻烦.我尝试了两种方法,两种方式都是同样的错误.

<link rel="stylesheet" type="text/css" href="css/header.css" />
<?php
$page = array("index.php", "about.php");
$names = array("Home", "About")


foreach($names as $name){
    echo "<a href=$page> $name </a>";
}

?>

<link rel="stylesheet" type="text/css" href="css/header.css" />
<?php
$page = array("index.php", "about.php");
$names = array("Home", "About")

foreach($page as $pages){
    foreach($names as $name){
        echo "<a href=$pages> $name </a>";
    }
}
?>
Run Code Online (Sandbox Code Playgroud)

php foreach header

4
推荐指数
2
解决办法
3万
查看次数

标签 统计

foreach ×1

header ×1

php ×1