PHP usort won't sort class

Finally, I discovered the source of this error. The problem was that this code was inside a class.

If that's your case, then you should call usort this way:

usort($items, array("MyClass", "compare_method"));

Furthermore, if your Class is in a namespace, you should list the full namespace in usort.

usort($items, array('Full\Namespace\WebPageInformation', 'compare_method'));

Also, you can set a static function inside your Class:

static myfunction($a, $b){'yoursort'}

and call it like this:

usort($items, "Class::myfunction");

Tags:

Php

Usort