Php if something equals x, y or z

I am writing some kind of php logic and I am trying to simplify something.

Is it possible to write something like the following:

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

      

I have to do it like this:

<?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 } ?>

      

Just want to know if I can simplify the below example. Thanks to

+3


source to share


2 answers


Make an array of values, then use in_array

.



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

      

+4


source


Just use in_array()



if (in_array(get_theme_mod('header_image_location'), array('x','y','z'))) {

}

      

+3


source







All Articles