您可以像这样简化您的代码:
<?php
$selectedRegions1 = array('ibiza','mallorca','menorca','andalucia','basque','cataluna', 'centralspain','greenspain','pyrenees','rioja','valencia');
$selectedRegions2 = array('brittany','burgundy','alps','aquitaine','loire','languedoc', 'paris','provence');
$selectedRegions3 = array('grancanaria','lapalma','lanzarote','tenerife');
$selectedRegions4 = array('atlas','essaouira','fez','marrakech');
if (in_array($region, $selectedRegions1 )) {
$GoTo = "/spain/".$region.".php";
}elseif(in_array($region,$selectedRegions2)) {
$GoTo = "/france/".$region.".php";
}elseif (in_array($region,$selectedRegions3)) {
$GoTo = "/canaries/".$region.".php";
}elseif (in_array($region,$selectedRegions4)) {
$GoTo = "/morocco/".$region.".php";
}
?>
您的代码的问题是您在“||”之后忘记了“$region ==”:
if ($region=='ibiza'|| $region=='mallorca'|| $region=='menorca'|| $region=='andalucia'|| $region=='basque'|| $region=='cataluna'|| $region=='centralspain'|| $region=='greenspain'|| $region=='pyrenees'|| $region=='rioja'|| $region=='valencia')