Re: sorting associative array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jochem Maas wrote:

Jeffery Fernandez wrote:

Jochem Maas wrote:

...


....

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 :-(


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 {

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 ;-)

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.net

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux