PHP usort() expects parameter 2 to be a valid callback, not in a class
If the code is not in a class, but you are using a namespace, usort expects the second parameter to have that namespace defined. But not in an array in similar style to using usort in a class.
This worked for me, where 'cmp' is the sorting function:
usort($arrayToSort, 'My\Full\Namespace\cmp');
I put the callback function inside the function in which I put the usort() and it worked.
function callerFn() {
if (!function_exists('callbackFn')) {
function callbackFn() {}
}
usort($arrayToSort, "callbackFn");
}
You can also do it as an unnamed function:
function callerFn() {
usort($arrayToSort, function() {} );
}
In case this helps, (&since this is top of Google), I had to do this
class MyObj{
var $Supplier;
function cmp($m, $n) {
if ($m->Supplier == $n->Supplier) {
return 0;
}
return ($m->Supplier < $n->Supplier) ? -1 : 1;
}
}
usort($arrayToSort, array('My\Full\Namespace\MyObj', 'cmp'));