So I've searched for hours but no thread seems to get me to a working solution.
My problem; I've got 2 arrays. 1 array with the user's roles. And one array with all roles with an specific order.
$roles = [
[
'id' => 22465,
'name' => 'Rank 1',
'position' => 24,
'color' => 16711680,
],
[
'id' => 59454,
'name' => 'Rank 2',
'position' => 15,
'color' => 15844367,
],
[
'id' => 62280,
'name' => 'Rank 3',
'position' => 2,
'color' => 65494,
],
[
'id' => 67139,
'name' => 'Rank 4',
'position' => 10,
'color' => 1146986,
],
[
'id' => 75372,
'name' => 'Rank 5',
'position' => 25,
'color' => 1146986,
],
[
'id' => 75373,
'name' => 'Rank 6',
'position' => 18,
'color' => 1146986,
],
];
And I have the user roles array:
$userdata = [
'roles' => [22465, 59454, 62280, 67139, 75372, 75373],
'data' => ['irrelevant']
];
I want the user roles array to be sorted to the roles 'position' in the other array. I think the bottleneck is in the part that the array has to be called with the subarray [roles][position] to get the order to work.
The result in the roles subarray should be:
[0] => 75372
[1] => 22465
[2] => 75373
[3] => 59454
[4] => 67139
[5] => 62280