好的,将usort与函数一起使用并不是那么复杂
这就是我以前在我的线性代码中所拥有的
function merchantSort($a,$b){
return ....// stuff;
}
$array = array('..','..','..');
要排序,我只是简单地
usort($array,"merchantSort");
现在我们正在升级代码,删除所有全局函数,并将它们放在适当的位置.现在所有的代码都在一个类中,我不知道如何使用usort函数对数组进行排序,参数是一个对象方法,而不是一个简单的函数
class ClassName {
...
private function merchantSort($a,$b) {
return ...// the sort
}
public function doSomeWork() {
...
$array = $this->someThingThatReturnAnArray();
usort($array,'$this->merchantSort'); // ??? this is the part i can't figure out
...
}
}
问题是如何在usort()函数中调用对象方法