As explained in another question, isset is, in fact, faster than in_array. in_array is O(n), whereas isset is O(1).
One way to use isset is to rewrite your array in the form:
$array = ['style-1' => true, 'style-2' => true, 'style-3' => true, 'style-4' => true, 'style-6' => true];
If you're only searching an array once, that's the best way to go about this. However, if you dislike the verbosity of that method, and you plan to check for the existence of an element multiple times, you could do this instead:
$array = ['style-1', 'style-2', 'style-3','style-4', 'style-6'];
$array = array_flip($array);
This will reverse the keys and values, so $array['style-1']
will be 0, $array['style-2']
will be 1, and so on. You can then either use isset or array_key_exists:
return array_key_exists( get_theme_mod( 'header_style' ), $array );
I've heard rumors that array_key_exists is faster than isset for this purpose as of PHP7, but I haven't actually looked at any benchmarks.