如何使用multi-dimensional
按自定义顺序对uksort
数组进行排序?
array
我需要订购 -
[subjectList] => Array
(
[The Academic Core - Science] => Array
(
[Genetics] => Array
(
[userId] => Array
(
[0] => 8q2hEPAvW2
)
)
)
[The Academic Core - Math] => Array
(
[Algebra] => Array
(
[userId] => Array
(
[0] => 7rC6Of5Ogl
)
)
[Trigonometry] => Array
(
[userId] => Array
(
[0] => gdhgyfd3xJ
)
)
[Geometry] => Array
(
[userId] => Array
(
[0] => gdhgyfd3xJ
)
)
)
)
自定义订单比较功能是 -
function sortSubject($a,$b){
$subarr = array('The Academic Core - Math'=>1,'The Academic Core - Science'=>2,'Algebra'=>3,'Geometry'=>4,'Genetics'=>);
$asortorder = $subarr[$a];
$bsortorder = $subarr[$b];
if ($asortorder == $bsortorder)
return 0;
return ($asortorder < $bsortorder) ? -1 : 1;
}