Imperialoutpost;10958616 wrote:Sorry if I'm wrong Johanafm, cos I haven't had much experience with array_intersect, but if you use it then you're still going to have to use something like in_array to find out if the phrase you wanted is in the array returned by array_intersect?
Oh no, you are indeed correct, and if you are checking for just one single word, you might as well do it the way you do.
But, if you want a list of everything contained in both arrays, or want to check for multiple words I find this approach to be simpler.
$arr = array('one', 'two', 'three');
$arr2 = array('one', 'three', 'four');
$isect = array_intersect($arr, $arr2);
echo 'These are in both: ' . print_r($isect,1) . '<br/>';
# and for every check you want to do from now on, there's just one array to check against
foreach($words_to_check as $w) {
if (in_array($w, $isect)) {
echo $w . ' is in both.<br/>'
}
}