2017-01-20 1 views
1

에 병합 후 작동하지 않습니다 나는 다음과 같은 코드가 있습니다에 usort 객체

$content->Vehicles = (object)array_merge((array)$content->List, (array)$content_new->List); 

$content->List$content_new->List는 두 개의 API 호출에서 생성되는 예상대로 모든 작업이입니다.

문제는 개체를 정렬해야합니다. 이렇게하려면 내가 사용 : 나는 $content->List에 통과하면 usort() expects parameter 1 to be array, object given에 그러나 $content->Vehicles 결과를 예상대로

usort($content->Vehicles, function($a, $b) { 
    return ($a->Score < $b->Score) ? -1 : (($a->Score > $b->Score) ? 1 : 0); 
}); 

가 작동합니다.

이것을 이해하고 싶습니다.

+1

개체가 아니라 배열을 정렬하십시오. –

답변

0

그럼 나는 지금 바보가되었습니다. 답은 다음과 같습니다 :

$content->Vehicles = array_merge((array)$content->List, (array)$content_new->List);