If you want to combine two arrays, you should use array_intersect()here.
If you want to check a specific value with in_array(), you need to use a loop here:
<?php
$res = $row['column_name'];
$field = explode(",", $res);
$arr = array('r1','r2','r3','r4','r5','r6');
foreach ($arr as $value) {
if(in_array($value, $field)) {
echo "success";
}
else{
echo "failed";
}
}
?>
According to the manual: in_array - checks if a value exists in the array
Also note that you have a syntax error in your array:
$arr = array('r1','r2,'r3','r4','r5','r6'); // missing quote here for r2
Update:
If you want to use array_intersect()how you can do it:
<?php
$arr1 = array('r1','r2');
$arr2 = array('r1','r2','r3','r4','r5','r6');
$result = !empty(array_intersect($arr1, $arr2));
if($result){
echo "true";
}
else{
echo "false";
}
?>
Demo
Update 2:
, , array_intersect(), , :
<?php
$arr1 = array('r2');
$arr2 = array('r1','r2','r3','r4','r5','r6');
$result = array_intersect($arr1, $arr2);
if(count($result)){
echo "Following ID(s) found: ".implode(",",$result);
}
?>
DEMO