什么';在PHP中,检查变量是否与一系列值中的一个匹配的最简洁的方法是什么?

什么';在PHP中,检查变量是否与一系列值中的一个匹配的最简洁的方法是什么?,php,comparison,Php,Comparison,我目前正在将此用于导航列表以突出显示活动页面: <?= ($current_page == 'thema_list' ? 'class="on"' : '') ?> 对于2个值,这可能是PHP处理它所需时间最快的方法,但如果您有很多值,可以在\u数组中使用: <?= (in_array($current_page, array('thema_list', 'thema_edit')) ? 'class="on"' : '') ?> 您可以在数组()中使用带有的数组。

我目前正在将此用于导航列表以突出显示活动页面:

<?= ($current_page == 'thema_list' ? 'class="on"' : '') ?>

对于2个值,这可能是PHP处理它所需时间最快的方法,但如果您有很多值,可以在\u数组中使用:

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

您可以在数组()中使用带有
的数组。


您能否将它们放入一个数组中,然后使用:

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