<?php
$sortLikeThis = [
'5',
'3',
'7',
'1'
];
$unsorted = [
[
'sort' => '7',
'name' => 'Test',
],
[
'sort' => '1',
'name' => 'Test 2',
],
[
'sort' => '3',
'name' => 'Test 3',
],
[
'sort' => '5',
'name' => 'Test 4',
],
[
'sort' => '7',
'name' => 'Test 4',
],
];
usort($unsorted, function($x, $y) use ($sortLikeThis)
{
return array_search($x['sort'], $sortLikeThis) - array_search($y['sort'], $sortLikeThis);
});
var_dump($unsorted);
preferences:
41.23 ms | 402 KiB | 5 Q