I have a multidimensional array in this structure:
$arr = [
0 => ['ref' => 'Q1'],
1 => ['ref' => 'C6'],
2 => ['ref' => 'C13'],
3 => ['ref' => 'S3'],
4 => ['ref' => 'Q11'],
8 => ['ref' => 'S7'],
9 => ['ref' => 'C4'],
];
I want to sort the array so that the order of values are S, Q, D, C, P, E and if possible have each alphanumeric ascending while also keeping the associate key [ref], like this:
$arr = [
0 => ['ref' => 'S3'],
1 => ['ref' => 'S7'],
2 => ['ref' => 'Q1'],
3 => ['ref' => 'Q11'],
4 => ['ref' => 'C4'],
8 => ['ref' => 'C6'],
9 => ['ref' => 'C13'],
];
usortanduasortboth accept a user-defined comparison function, so they deal with whatever you tell them to deal with.