Re: sorting associative array
| From: | Jeffery Fernandez | Date: | Mon, 24 Jan 2005 13:08:17 +0000 |
| Subject: | Re: sorting associative array | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-207119@lists.php.net to get a copy of this message | ||
Jochem Maas wrote:
Jeffery Fernandez wrote:I had done the changes to the variable declaration and also changed the constructor name to be the name of the class and it still gave me errors. Perhaps I will test it without any Error reporting on... needs some tweaking I guess. cheers, Jeffery Fernandez http://melbourne.ug.php.netJochem Maas wrote:...I did change it for php5 (to get rid of E_STRICT warnings IIR) - but the change was fairly cosmetic: the class def starts like: class MDASort {....Yes the example sent by Kurt Yoder worked for me. I coudn't work out the errors with the class you sent me. I realised it was written for PHP5 in mind ?... or maybe I wasn't patient enough to spent time debugging it :-(private $dataArray; //the array we want to sort. private $sortKeys; //the order in which we want the array to be sorted.if you change that to: class MDASort {var $dataArray; //the array we want to sort. var $sortKeys; //the order in which we want the array to be sorted.then the class should work under php4 as advertised (adding an '&' as you do below in the callback definition wouldn't hurt either). ...and within my class I am calling the following two lines: // Sort the array $this->mArraySortKey = 'score'; usort($this->mSearchData, array(& $this, 'sort_array'));cool, taking apart someone elses code and rewriting it one of the best ways of learning/understanding IMHO. btw the '&' before $this is not strictly required, but it should save you a few cycles :-) You always learn by re-writing someone elses code ;-)