I have two multidimensional arrays:
$arr_one = [
[
'param_one' => 'qwe',
'param_two' => 'yellow'
],[
'param_one' => 'xyz',
'param_two' => 'blue'
],[
'param_one' => 'abc',
'param_two' => 'pink'
]
...
];
$array_two = [
[
'param_one' => 'xyz',
'param_two' => 'blue'
],[
'param_one' => 'abc',
'param_two' => 'pink'
]
...
];
Each one of this arrays has around 20.000
elements in it. I want to see which elements (sub-array) -including all its elements - is in the first array (array_one
) but is not present in the second array (array_two
).
For this i've made this function:
function search_arr($needle, $haystack){
$needle = array_values($needle);
foreach ($haystack as $k => $v){
if ( array_search($needle[0], $v) ){
if ( array_search($needle[1], $v) ){
return true;
}
}
}
return false;
}
And i am using it this way:
foreach($array_one as $arr){
if(!search_arr($arr, $array_two)){
$unique[] = $arr;
}
}
It works well for small arrays but in my case because each array has around 20.000
sub-arrays it takes forever to go trough all of them :(
Is there a solution that will allow me to check which sub-array (with all its elements) exists in array_one
but doesn't exist in array_two
?