I have two multidimensional arrays what I want to merge but, I want to skip the same values during merging. I tried several different ways what I find on the web, but nothing help me in my case.
My initial array is much bigger than this one, but here I just put an example:
$array1 = [
"aaa" => [
"aa1"=> [
"key1"=> "value1",
"key2"=> "value2",
],
"bbb"=> [
"bb1",
"bb2",
],
"ccc"=> [
"cc1",
],
],
"ooo" => [
"oo1"
]
];
And another one, which I want to merge in the first one:
$array2 = [
"aaa" => [
"bbb"=> [
"bb2",
],
"ccc"=> [
"cc2",
],
],
];
print_r of the array_merge_recurisive, using the method like:
print_r(array_merge_recursive($array1, $array2));
Array
(
[aaa] => Array
(
[aa1] => Array
(
[key1] => value1
[key2] => value2
)
[bbb] => Array
(
[0] => bb1
[1] => bb2
[2] => bb2
)
[ccc] => Array
(
[0] => cc1
[1] => cc2
)
)
[ooo] => Array
(
[0] => oo1
)
)
So, in the result as you can see array bbb have two bb2 values, but I need just one
array_unique (array_merge_recursive($arr1, $arr2));