Reputation: 5
Basically I have this:
<?php
$variable = 8;
if ( $variable == array(5,6,7) ) :
echo '<p>'.$variable.'</p>;
endif;
?>
Can I test if a variable is one of those values like that or do I have to test each individually, like:
<?php
$variable = 8;
if ( ( $variable == 5 ) || ( $variable == 6 ) ) :
echo '<p>'.$variable.'</p>;
endif;
?>
Thanks.
Upvotes: 0
Views: 898
Reputation: 21575
I think you're looking for in_array()
:
if(in_array($variable, array(5,6,7) )){
// $variable is in the array!
}
Upvotes: 3