I am trying to make a foreach code that automatically makes my header for my site. The idea is that as I add more pages I can just add them to the array and it will auto update the header for me. Usually my foreach'es work but for the first time I am having trouble. I tried it two ways, both of which spat out the same error.
<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>";
}
}
?>
Usually when PHP returns "unexpected" it means the thing before it is not quite right, as with this case:
You have $names = array("Home", "About")
<-- no semi colon to end the line, and so the next line foreach
is unexpected, as it was "expecting" a ;
And looks like you've copy/pasted the mistake (missing semi colon) to other places in your code too
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With