note 3151 modified in usort by ronabop

From: Date: Wed, 18 Oct 2000 05:43:30 +0000
Subject: note 3151 modified in usort by ronabop
Groups: php.notes 
Request: Send a blank email to php-notes+get-6646@lists.php.net to get a copy of this message
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. http://www.php.net/manual/function.usort.php

« previous php.notes (#6646) next »