I have 2 arrays that I want to merge by the id of the object:

```
$object1->id = "1234"
$object2->id = "34553"
object3->id = "432"
array1 = [$object1,$object2]
array2 = [$object3,$object2]

```

My desired result: 

```
array3 = [$object1,$object2,$object3]

```

I tried to follow these instructions that I found:

```
//both arrays will be merged including duplicates
$result = array_merge( $array1, $array2 );
//duplicate objects will be removed
$result = array_map("unserialize", array_unique(array_map("serialize", $result)));
//array is sorted on the bases of id
sort( $result );

```

But it did not work (its just returns a merged array with duplicates objects)