Re: Sorting Objects in an array by object properties

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

 



Reto M. Kiefer wrote:
...
PS: The array has the following structure:

Array (
[0] => mail_Header Object ( [id] => 1 [pid] => 1 [read] => r [flagged] => n [from] => reto@xxxxxxxxxxx [subject] => Re: [ugffm] TYPO3 anybody ? [sendtime] => 2005.05.17 - 18:27:25 )
[1] => mail_Header Object ( [id] => 2 [pid] => 1 [read] => r [flagged] => n [from] => reto@xxxxxxxxxxx [subject] => Re: [ugffm] website [sendtime] => 2005.05.17 - 19:13:26 )


....
)

For certain you will want to use usort, maybe something like:

<?php

usort($your_array, 'sort_by_sendtime');

function sort_by_sendtime($mailObj1, $mailObj2) {
  if ($mailObj1->sendtime == $mailObj2->sentime) {
    return 0;
  }
  return ($mailObj1->sendtime < $mailObj2->sendtime) ? -1 : 1;
}

?>

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