PHP定制使用uksort排序多维数组

时间:2016-02-25 05:47:32

标签: php arrays sorting

如何使用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;                


}

0 个答案:

没有答案