在 php 中使用 usort 和类私有函数
ok 使用带有函数的 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()函数中调用对象方法