Home > php教程 > PHP源码 > 自定义排序在class里的运用

自定义排序在class里的运用

PHP中文网
Release: 2016-05-25 17:12:22
Original
1047 people have browsed it

跳至

 $b) ? -1 : 1;
    }
}

class a {
    
    function c($a, $b) {
        $a = $a['a'];
        $b = $b['a'];
        echo $a . '_' . $b . '|';
        if ($a == $b) {
            return 0;
        } else {
            return ($a > $b) ? -1 : 1;
        }
    }
    
    public static function b() {
        $arr = array(
            array('a' => '1'),
            array('a' => '2'),
            array('a' => '3'),
            array('a' => '4'),
            array('a' => '5'),
            array('a' => '6'),
            array('a' => '7')
        ); 
        
        //uasort($arr, "c"); // 回调函数c跟d是一样的,但是在这种情况,c是不能用的。
        uasort($arr, "d");
        
        print_r($arr);
    }
}

a::b();
?>
Copy after login

                   

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template