I have the following code:
$content->Vehicles = (object)array_merge((array)$content->List, (array)$content_new->List);
The $content->List
and $content_new->List
are created from two API calls and is all working as expected.
The problem is I need to sort the object. To do so I use:
usort($content->Vehicles, function($a, $b) {
return ($a->Score < $b->Score) ? -1 : (($a->Score > $b->Score) ? 1 : 0);
});
When I pass in $content->List
it works as expected however $content->Vehicles
results in usort() expects parameter 1 to be array, object given
.
Would love to figure this one out.