I am writing out some php logic, and I'm 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 must I 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 bottom example. Thanks
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 } ?>
Just use in_array()
if (in_array(get_theme_mod('header_image_location'), array('x','y','z'))) {
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With