This is a simple way to sort based on a "priority list":
<?php
$order = [1,3,0,2];
$arr = [
[ 'id' => 0 ],
[ 'id' => 1 ],
[ 'id' => 2 ],
[ 'id' => 3 ],
];
uasort(
$arr,
function ($a, $b) use ($order) {
return array_search($a['id'], $order) <=> array_search($b['id'], $order);
}
);
print_r($arr);
?>
This will return:
Array
(
[1] => Array
(
[id] => 1
)
[3] => Array
(
[id] => 3
)
[0] => Array
(
[id] => 0
)
[2] => Array
(
[id] => 2
)
)
Note that if you have a value in $arr that is not on the $order list, you will need additional checks since the array_search function returns FALSE for undefined indexes.