I have two different array. The array are like
first array is like
Array
(
[0] => Array
(
[source_language] => English
[target_language] => Array
(
[0] => German
[1] => Norwegian
)
[title] => file 1.xlsx
[file_name] => 1461911750_file_test.xlsx
)
[1] => Array
(
[source_language] => Hindi
[target_language] => Array
(
[0] => Belarusian
)
[title] => new files.xlsx
[file_name] => 1461912206_file_here_files.xlsx
)
)
Second array is like
Array
(
[1] => Array
(
[source_language] => English
[target_language] => Array
(
[0] => Urdu
[1] => Hindi
)
)
[2] => Array
(
[source_language] => Hindi
[target_language] => Array
(
[0] => Norwegian
)
)
[3] => Array
(
[source_language] => Hindi
[target_language] => Array
(
[0] => German
)
)
[3] => Array
(
[source_language] => English
[target_language] => Array
(
[0] => German
[1] => Norwegian
)
)
)
Now you can both array same key for source_langauge
and target_language
. The title
and file_name
key is available only in first array
So I want that the first array will search all the source_language and target_language from the second array and show both matching arrays and non matching arrays
So the output should be like this
The matching array is
[0] => Array
(
[source_language] => English
[target_language] => Array
(
[0] => German
[1] => Norwegian
)
[title] => file 1.xlsx
[file_name] => 1461911750_file_test.xlsx
)
as it has same values source language and target language in second array
The other result will show is
non matching array is
[0] => Array
(
[source_language] => Hindi
[target_language] => Array
(
[0] => Belarusian
)
[title] => new files.xlsx
[file_name] => 1461912206_file_here_files.xlsx
)
as this source language and target languages are not found in second array.
Update
I have tried so far is
$diffs = [];
foreach ($first_array as $a1) {
$h1 = md5(json_encode($a1));
$found = false;
foreach ($second_array as $a2) {
if (md5(json_encode($a2)) == $h1) {
$found = true;
break;
}
}
if ( !$found ) {
$diffs []= $a1;
}
}
But this one is not working at all