繁体   English   中英

除了一个循环外,获取全部

[英]Get all but one loop

我正在创建一个名为get_other_sites的函数。 但是我认为有比现在更好或更快的方法。

function get_other_sites($curent_site){
    if ($curent_site == 'site1.com'){
        echo"
            <a href='site2.com'>site2.com</a>
            <a href='site3.com'>site3.com</a>
            <a href='site4.com'>site4.com</a>
            <a href='site5.com'>site5.com</a>
            ";
    }
    else if ($curent_site == 'site2.com'){
        echo"
            <a href='site1.com'>site1.com</a>
            <a href='site3.com'>site3.com</a>
            <a href='site4.com'>site4.com</a>
            <a href='site5.com'>site5.com</a>
            ";
    }
    else if ($curent_site == 'site3.com'){
        echo"
            <a href='site1.com'>site1.com</a>
            <a href='site2.com'>site2.com</a>
            <a href='site4.com'>site4.com</a>
            <a href='site5.com'>site5.com</a>
            ";
    }
}

对于这个问题,我使其更易于阅读,但网站列表要长得多。 有人知道做这件事的更好的方法吗?

提前致谢。

$current_site="def.com"; // testing
$sites=array("abc.com","def.com","ghi.com","jkl.com");
foreach($sites as $site){
     if($current_site!=$site)
       echo "<a href='$site'>$site</a>";
}

就这么简单:P

小提琴

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM