$all = array
(
    0 => 307,
    1 => 157,
    2 => 234,
    3 => 200,
    4 => 322,
    5 => 324
);
$search_this = array
(
    0 => 200,
    1 => 234
);

I would like to find out if $all contains all $search_this values and return true or false. any idea please?

share|improve this question

55% accept rate
feedback

2 Answers

up vote 3 down vote accepted

Look at array_intersect()

<?php
$containsSearch = count(array_intersect($search_this, $all)) == count($search_this);
share|improve this answer
thanks, it works! :) – peter Mar 11 at 14:36
feedback

I think you're looking for the intersect function

array array_intersect ( array $array1 , array $array2 [, array $ ... ] )
array_intersect() returns an array containing all the values of array1 that are 
present in all the arguments. Note that keys are preserved.

http://www.php.net/manual/en/function.array-intersect.php

share|improve this answer
thanks, it works! :) – peter Mar 11 at 14:37
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.