033-PHP对一个数组先奇后偶,然后再进行从大到小排序

<?php
    function Compare($str1, $str2) {
        if (($str1 % 2 == 0) && ($str2 %2 == 0)) {
            if ($str1 > $str2)
                return - 1;
            else
                return 1;
        }
        if ($str1 % 2 == 0)
            return 1;
        if ($str2 % 2 == 0)
            return -1;
        return ($str2 > $str1) ? 1 : - 1;
    }
    $scores = array (22,57,55,12,87,56,54,11);
    usort ( $scores, 'Compare' );
    print_r ( $scores );
?>

 

posted @ 2019-06-08 20:53  像一棵海草海草海草  阅读(219)  评论(0编辑  收藏  举报