Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
$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
add comment (requires an account with 50 reputation)

2 Answers

up vote 16 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 '12 at 14:36
add comment (requires an account with 50 reputation)

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 '12 at 14:37
add comment (requires an account with 50 reputation)

Your Answer

 
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.