Using usort in php with a class private function

后端 未结 5 964
闹比i
闹比i 2020-12-02 07:10

ok using usort with a function is not so complicated

This is what i had before in my linear code

function merchantSort($a,$b){
    return ....// stuf         


        
5条回答
  •  一向
    一向 (楼主)
    2020-12-02 08:09

    Make your sort function static:

    private static function merchantSort($a,$b) {
           return ...// the sort
    }
    

    And use an array for the second parameter:

    $array = $this->someThingThatReturnAnArray();
    usort($array, array('ClassName','merchantSort'));
    

提交回复
热议问题