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

Popular posts from this blog

javascript - Unusual behaviour when drawing lots of images onto a large canvas -

how can i manage url using .htaccess in php? -

javascript - Chart.js - setting tooltip z-index -