我正在写一些 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)
只是想知道我是否可以简化底部的示例。谢谢
创建一个值数组,然后使用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)
| 归档时间: |
|
| 查看次数: |
2114 次 |
| 最近记录: |