Wednesday, 6 March 2019

How to merge two arrays of object in PHP

https://stackoverflow.com/questions/11877586/how-to-merge-two-arrays-of-object-in-php


//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 );

No comments:

Post a Comment