nav-menu
。 <nav id="nav">
<ul class="container">
<?php foreach(array_unique(array_values($continent)) as $continent_id){
if($continent_id == 1 ) $continent = "Europe" ;
elseif ($continent_id == 2 ) $continent = "Asia" ;
elseif ($continent_id == 3 ) $continent = "North America" ;
elseif ($continent_id == 4 ) $continent = "Oceania" ;
elseif ($continent_id == 5 ) $continent = "South America" ;
else $continent == "Africa" ;
?>
<!-- HTML go here -->
<li><a href="#<?php echo $continent ; ?>"><?php echo $continent ; ?> </a></li>
<?php } ?>
</ul>
</nav>
错误消息说:array_values()期望参数1为数组,给定字符串!
有人能告诉我我错过了什么吗?
答案 0 :(得分:1)
我解决了。好极了 !谢谢大家的意见。 :d。你们真棒。
<!-- Nav -->
<nav id="nav">
<ul class="container">
<?php
foreach(array_unique(array_values($continent)) as $continent_id){
if($continent_id == 1 ) $continent_name = "Europe" ;
elseif ($continent_id == 2 ) $continent_name = "Asia" ;
elseif ($continent_id == 3 ) $continent_name = "North America" ;
elseif ($continent_id == 4 ) $continent_name = "Oceania" ;
elseif ($continent_id == 5 ) $continent_name = "South America" ;
else $continent_name == "Africa" ;
?>
<li><a href="#<?php echo $continent_name ?>"><?php echo $continent_name ?> </a></li>
<?php }?>
</ul>
</nav>
答案 1 :(得分:0)
$continent = "Europe"
在第一个循环中你将数组更改为字符串 - 所以恕我直言你应该将$ continent更改为其他东西; - )