This seems straightforward, but the below code is giving the following error. Any suggestions?
usort() expects parameter 2 to be a valid callback, function 'cmp' not found or invalid function name
My code:
function cmp($item1, $item2) {
return strcmp(strtolower($item1->last_name), strtolower($item2->last_name));
}
public function get_people() {
usort($this->my_array, 'cmp');
}
Since you use
$this->my_array
and the function has the keyword public, I'm going to assume these two methods are in a class definition, so you also have to define, that you want to call a class method and not a normal function.This means you have to change:
to: