You are here: Re: Sorting Objects in an array by object properties « PHP « IT news, forums, messages
Re: Sorting Objects in an array by object properties

Posted by Jason Barnett on 05/27/05 19:32

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@nerdbude.de [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@nerdbude.de [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;
}

?>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация