note 3151 deleted from function.usort by didou
| From: | didou@php.net | Date: | Sat, 09 Aug 2003 15:26:52 +0000 |
| Subject: | note 3151 deleted from function.usort by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-53743@lists.php.net to get a copy of this message | ||
Note Submitter: roads@free.fr
----
Please note that you cannot use a
class member function as your comparison function for usort().
The following will not call the comparison function *at all*, leaving your array unsorted :
class DummyClass{
function myCmp($a,$b){
// ... compare code
}
function method($args){
// Declare your array
$myArray[]=Array(...)
// Sort the array
usort($myArray[],$this->myCmp);
// At this point, the array is
// still unsorted !
}
}
If you declare the function out of DummyClass, this code will work.