$posP600Stock = [];//tablica obiektów w której każyd posiada metodę getWarehouseId
$warehouseIdsPriorities = [34,33,12,6];//priorytety sortowania !!! pamietaj o array flip !!!
usort(
$posP600Stock,
function ($d1, $d2) use ($warehouseIdsPriorities) {
return $warehouseIdsPriorities[$d1->getWarehouseId()] >= $warehouseIdsPriorities[$d2->getWarehouseId()] ? 1 : -1;
//lub return $warehouseIdsPriorities[$d1->getWarehouseId()] <=> $warehouseIdsPriorities[$d2->getWarehouseId()] ;
}
);
//wynik pososrtowany po wartościach z drugiej tablicy
<?php
$data = [
['mag' => 3, 'value' => 22],
['mag' => 3, 'value' => 33],
['mag' => 5, 'value' => 44],
['mag' => 9, 'value' => 4444],
['mag' => 3, 'value' => 55],
['mag' => 4, 'value' => 554343],
['mag' => 9, 'value' => 234324],
];
$sort = [9,3,4,5];
$orderIdKeys = array_flip($sort);
usort($data, function ($u1, $u2) use ($orderIdKeys) {
return $orderIdKeys[$u1['mag']] >= $orderIdKeys[$u2['mag']] ? 1 : -1;
//lub $orderIdKeys[$u1['mag']] <=> $orderIdKeys[$u2['mag']];
});
var_dump($data);