我在代码中执行此if
语句,以便在支票内的页面上添加横幅<div>
。我怎样才能更好地整理这些代码?
$currentpage = $_SERVER['REQUEST_URI'];
if($currentpage=="/" || $currentpage=="/en" || $currentpage=="/pl" || $currentpage=="/cz" || $currentpage=="/index.php" || $currentpage=="/index.php/" || $currentpage=="" ||
$currentpage=="/en/index.php" || $currentpage=="/en/index.php/" ||
$currentpage=="/pl/index.php" || $currentpage=="/pl/index.php/" ||
$currentpage=="/cz/index.php" || $currentpage=="/cz/index.php/" ||
$currentpage=="/flyeuro/en/index.php/" || $currentpage=="/flyeuro/en/index.php" ||
$currentpage=="/flyeuro/pl/index.php/" || $currentpage=="/flyeuro/pl/index.php" ||
$currentpage=="/flyeuro/cz/index.php/" || $currentpage=="/flyeuro/cz/index.php")
{
答案 0 :(得分:2)
你可以这样做:
<?php
// add your all URLs to an array
$urls = array("/en/index.php", "/en/index.php/", "/", "/en");
if(in_array($currentpage, $urls)) {
echo "It exists";
} else {
echo "It does not exist";
}
?>