After a 033-PHP array to parity, and then the descending order

<?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 );
?>

 

Guess you like

Origin www.cnblogs.com/tianpan2019/p/10991667.html