<?php
function sort_custom(&$array)
{
$hierarchy = array_flip([
"organization",
"company",
"group",
"unit",
"sub_unit",
"team"
]);
uksort($array, fn($a, $b) => $hierarchy[$a] <=> $hierarchy[$b]);
}
$array = [
"team" => "team1",
"organization" => "organization1",
"group" => "group1"
];
sort_custom($array);
var_export($array);
- Output for 7.4.10 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
- array (
'organization' => 'organization1',
'group' => 'group1',
'team' => 'team1',
)
- Output for 7.0.0, 7.1.0
- Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ',' or ')' in /in/MF7X6 on line 14
Process exited with code 255. - Output for 5.6.40
- Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW) in /in/MF7X6 on line 14
Process exited with code 255.
preferences:
96.27 ms | 408 KiB | 5 Q