php 如果某个值等于 x、y 或 z

Sam*_*row 4 php if-statement

我正在写一些 php 逻辑,并且我正在尝试简化一些东西。

是否可以写如下内容:

<?php if( (get_theme_mod('header_image_location')=='x', 'y' or 'z' ) {?> 
    //Do something 
<?php } ?>
Run Code Online (Sandbox Code Playgroud)

我必须这样做:

<?php if( (get_theme_mod('header_image_location')=='x') ||  (get_theme_mod('header_image_location')=='y') || (get_theme_mod('header_image_location')=='z') ) {?> 
    //Do something 
<?php } ?>
Run Code Online (Sandbox Code Playgroud)

只是想知道我是否可以简化底部的示例。谢谢

Roc*_*mat 5

创建一个值数组,然后使用in_array.

<?php if( in_array(get_theme_mod('header_image_location'), array('x', 'y', 'z'))){?> 
    //Do something 
<?php } ?>
Run Code Online (Sandbox Code Playgroud)