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
}
}