note 54901 added to function.usort

From: Date: Tue, 19 Jul 2005 09:09:46 +0000
Subject: note 54901 added to function.usort
Groups: php.notes 
Request: Send a blank email to php-notes+get-92150@lists.php.net to get a copy of this message
The easiest way to compare two integers is just to take the second away from the first. For example, say you wanted to sort by an integer property of an object. Your comparison function would look like this: <?php function compare_counts($a, $b) { return $a->count - $b->count; } ?> This works because you don't necessarily have to return -1, 0 or 1, the manual states any integer less than, equal to or greater than 0 is OK. ---- Manual Page -- http://www.php.net/manual/en/function.usort.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54901 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54901&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54901&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54901&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54901&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54901&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54901&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54901&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#92150) next »