Jump to content
Larry Ullman's Book Forums

Why Is This Being Used Differently Than In The Manual?


Recommended Posts

Guest Deleted

A friend pointed out that the manual says usort callback functions are supposed to return 1 or -1. I was wondering why Larry has them return true or false?

 

This is from page 3:

function asc_number_sort($x,$y) {
if ($x['key1'] > $y['key1']) {
return true;
} elseif ($x['key1'] < $y['key1'])
return false;
} else {
return 0;
)

usort($a, 'asc_number_sort'); 

From the manual: "The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second." (http://us3.php.net/usort)

Link to comment
Share on other sites

 Share

×
×
  • Create New...