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

自定义排序在class里的运用

PHP中文网
PHP中文网Original
2016-05-25 17:12:221045browse

跳至

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

                   

Statement:
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
Previous article:用PHP将文本转换Web页面Next article:php分页注释版