Php in_array search for more than 1 string

Hello forums

I have this array :

$a = array(1=>red,2=>blue,3=>green,4=>black);

I want to see if blue and red is in the array;

I tried:

if (in_array('red,blue',$a)){
  echo 'Yes';
   echo 'Nope';

But it’s returning false. I need it like: when red exists in the array and blue does’t it will return false, meaning red and blue must be in the array to return true. is there a proper way to do this?


Ok I figured a dirty solution

$a = array(1=>'red',2=>'blue',3=>'green');
$s = array(1=>'red',2=>'blue');

$c = count($s);
foreach($s as $k=>$v){
  if($i==$c){$i=0; return true;}else( return false;); 

Eeek… anyone has a better one? Please share


Maybe something like this?

function values_in_array(array $needles, array $haystack){
  return count($needles) === count(array_intersect($needles, $haystack));

$haystack = array('yellow', 'red', 'green', 'blue');

  values_in_array(array('red', 'purple'), $haystack)
); # bool(false)

  values_in_array(array('red', 'blue'), $haystack)
); # bool(true)

Wow array_intersect is much cleaner than looping
You rule!