Re: sorting associative array
| From: | Jochem Maas | Date: | Mon, 24 Jan 2005 12:40:13 +0000 |
| Subject: | Re: sorting associative array | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-207118@lists.php.net to get a copy of this message | ||
Jeffery Fernandez wrote:
Jochem 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 :-)
cheers, Jeffery Fernandez http://melbourne.ug.php.net