php - Check if any of values exists in array -
want shorten code
if( (in_array('2', $values)) or (in_array('5', $values)) or (in_array('6', $values)) or (in_array('8', $values)) ){ echo 'contains 2 or 5 or 6 or 8'; } tried
(in_array(array('2', '5', '6', '8'), $values, true)) but understand true if values exists in array
please, advice
try array_intersect(), eg
if (count(array_intersect($values, array('2', '5', '6', '8'))) > 0) { echo 'contains 2 or 5 or 6 or 8'; } example here - http://codepad.viper-7.com/gfilgx
Comments
Post a Comment