Jump to content

Warning: usort() expects parameter 2 to be a valid callback


earachefl

Recommended Posts

Probably missing something really stupid here. My usort function:

private function compareLastName($x, $y) {
	if($x['Name'] == $y['Name']) {
		return 0;
	} elseif ($x['Name'] < $y['Name']) {
		return -1;
	} else {
		return 1;
	}
}

is being called in this function, same file:

public function loadAll() {
	//various SQL stuff
	$arrayNoNulls = $stmt->fetchAll();
	//various SQL stuff	
	$arrayNulls = $stmt->fetchAll();

	$arrayAll = array_merge($arrayNoNulls, $arrayNulls);
	usort($arrayAll, "compareLastName");
                print_r($arrayAll);
}

The page outputs the unsorted array, preceded by the warning. What am I missing?

I assume these are in the same class?  If so:

 

usort(array($this, 'compareLastName'));

 

Yes, these are in the same class. Trying this I get "Fatal error: Only variables can be passed by reference".

Not sure I understand. Does the function "compareLastName()" need to be in a different place?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.