我正在写一些 php 逻辑,我正在尝试简化一些事情。
是否可以这样写:
<?php if( (get_theme_mod('header_image_location')=='x', 'y' or 'z' ) {?>
//Do something
<?php } ?>
我必须这样做:
<?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 } ?>
只是想知道我是否可以简化底部示例。谢谢
最佳答案
创建一个值数组,然后使用 in_array
。
<?php if( in_array(get_theme_mod('header_image_location'), array('x', 'y', 'z'))){?>
//Do something
<?php } ?>
关于php 如果某项等于 x、y 或 z,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27661047/