Given the following arrays:
$array[0]['tid'] = 'valueX';
$array[1]['tid'] = 'valueY';
$array2[0]['tid'] = 'valueZ';
$array2[1]['tid'] = 'valueY';
My goal is to check if any of the values in $array
are in $array2
Below is what I came up with but I'm wondering if there is a easier / better solution?
Maybe something that gets only the values of an array or removes the 'tid'
key.
foreach($array as $arr) {
$arr1[] = $arr['tid'];
}
$flag = 0;
foreach($array2 as $arr) {
if( in_array( $arr['tid'], $arr1 ) ) {
$flag++;
}
}
echo $flag; // number of duplicates