2009-09-24 70 views

回答

3

爲2倍的值,這可能是對所花費的時間PHP來處理它的量最快的方法,但是如果你有很多的值,你可以使用in_array:

<?= (in_array($current_page, array('thema_list', 'thema_edit')) ? 'class="on"' : '') ?> 

還檢查了this question關於與in_array相關的一些速度測試,而不是單獨檢查每個值。

0

你可以使用一個數組in_array()

$matches = array("thema_list", "thema_edit", "thema_other"); 
if (in_array($current_page, $matches)) { 
    echo 'class="on"' 
} 
0

你可以把它們放入數組,然後使用:

if(in_array($current_page, $array_values)) 
{ 
    echo 'class on'; 
} 
相關問題