is there a native php function to see if one array of values is in another array?

Posted by Haroldo on Stack Overflow See other posts from Stack Overflow or by Haroldo
Published on 2010-04-21T18:19:16Z Indexed on 2010/04/21 18:23 UTC
Read the original article Hit count: 233

Filed under:

Is there a better method than loop with strpos()?

Not i'm looking for partial matches and not an in_array() type method.

example needle and haystack and desired return:

$needles[0] = 'naan bread';
$needles[1] = 'cheesestrings';
$needles[2] = 'risotto';
$needles[3] = 'cake';

$haystack[0] = 'bread';
$haystack[1] = 'wine';
$haystack[2] = 'soup';
$haystack[3] = 'cheese';

//desired output - but what's the best method of getting this array?
$matches[0] = 'bread';
$matches[1] = 'cheese';

© Stack Overflow or respective owner

Related posts about php