peter peter - 4 months ago 34
PHP Question

php check if array contains all array values from another array

$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?

Answer

Look at array_intersect().

$containsSearch = count(array_intersect($search_this, $all)) == count($search_this);
Comments