<?php $records = [(object)['id' => 1], (object)['id' => 2], (object)['id' => 3]]; $sorted = ['2' => 7, '3' => 4, '1' => 2]; $tempArr = array(); foreach ($records as $value) { $tempArr[$value->id] = $value; // $value IS an object } $resultArr = array_values(array_replace($sorted, $tempArr)); var_export($resultArr);
You have javascript disabled. You will not be able to edit any code.