如何在php数组中调用下面的函数
我试图在一个类中使用它。我的比较函数叫做比较。在类中,我将使用$this->compare调用函数。但是,我不知道如何在usort中调用类函数 我试过:如何在php数组中调用下面的函数,php,arrays,Php,Arrays,我试图在一个类中使用它。我的比较函数叫做比较。在类中,我将使用$this->compare调用函数。但是,我不知道如何在usort中调用类函数 我试过: usort($array, this->compare); usort($array, "this->compare"); usort($array, this->"compare"); usort($array, compare); usort($array, "compare"); 以下是功能: function com
usort($array, this->compare);
usort($array, "this->compare");
usort($array, this->"compare");
usort($array, compare);
usort($array, "compare");
以下是功能:
function compare($x, $y)
{
if ( $x[0] == $y[0] )
return 0;
else if ( $x[0] < $y[0] )
return -1;
else
return 1;
}
此处记录:
此处记录:您尝试过这个吗
usort($array, array($this, 'compare'))
.你试过这个吗
usort($array, array($this, 'compare'))
见:
请参阅:您是这样做的
usort($a, array("InstanceName", "Method"));
您还可以发送实例(如果有的话),这样就可以发送$this
usort($a, array($this, "Method"));
一个更大的代码示例在中,您可以这样做
usort($a, array("InstanceName", "Method"));
您还可以发送实例(如果有的话),这样就可以发送$this
usort($a, array($this, "Method"));
中有一个更大的代码示例