I have two arrays which I merge using:
$query = array_merge($query1, $query2);
After merging I want to apply array unique:
$query = array_unique($query);
For some reason it gives me a php error, a page black.
I suspect it’s because of the structure of the array’s that need merging.
A vardump illustrates the structure of query1 and query 2:
array(73) {
[0]=> object(stdClass)#32 (6) {
["pic0"]=> string(78) "the picture1 link"
["bio"]=> string(22) "the bio1"
}
[1]=> object(stdClass)#96 (6) {
["pic0"]=> string(70) "the picture2 link"
["bio"]=> string(225) "the bio2"
}
}
array_uniqueworks by comparing the elements as strings. Objects generally can’t be converted to strings, so you are getting an error.Try using arrays instead of
stdClasses, and also make sure you set theSORT_REGULARflag.