检查数组值是否存在于另一个数组中[关闭]

I have 2 fields in a table

filed1               | filed2
ahmed,join,maya,omar | omar,maya

I get data by 2 array , I want check if Each value in $array1 the present in $array2 or not

in my case : if $array1[omar] present in $array2 or not , if $array1[maya] present in $array2 or not .. elc

That's my code , not worked ...What's wrong in it ?

$query = $db->query_first("SELECT * FROM table ");
$array1 = explode(",",$query[filed1]);
$array2 = explode(",",$query[filed2]);

foreach($array1 as $value)
{
    if (in_array($value,$array2))
    {
        //true
    }else{
        //false
    }
}

output of array1 :

Array ( [0] => maya [1] => omar [2] => ahmed [3] => join)

output of array2 :

Array ( [0] => omar [1] => maya )

I have known the cause of the problem, not in the code ... Content of the field at the base value of each line separately So used str_replace to delete the line

$query = $db->query_first("SELECT * FROM table ");
$array1 = explode(",",$query[filed1]);
$array1 = str_replace("
","",$array1);
$array2 = explode(",",$query[filed2]);
$array2 = str_replace("
","",$array2);

foreach($array1 as $value)
{
    if (in_array($value,$array2))
    {
        //true
    }else{
        //false
    }
}

As @MarkBaker said, you want to use array_intersect:

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

In your case:

$array1 = explode(",",$query[filed1]);
$array2 = explode(",",$query[filed2]);

$intersect = array_intersect($array1, $array2);

Since you asked, to check if this array is empty or not do the following:

if (empty($intersect))
    echo 'It is empty';