Re: Ack. Is sorting this array possible?
| From: | (Richard Lynch) | Date: | Tue, 04 Jul 2000 00:47:41 +0000 |
| Subject: | Re: Ack. Is sorting this array possible? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-4622@lists.php.net to get a copy of this message | ||
In article <8jg0bp$r3r$1@toye.php.net>, fn@csh.rit.edu ("C. Marcera") wrote:
> Greetings,
> Thanks for taking the time to look at this! I'm not too good with
> anything more than a simple one-dimensional array... Doh!
>
> I have text files with dates in them. I open the file, read the date and put
> the date and the file into an array. I want to sort the array by the date in
> the file so that when I use a for() loop I can display them in an HTML <UL>
> in the order of the dates in the file, the newest on top. As of now, the
> array looks like this:
>
> >$key = mktime( 0, 0, 0, $test_month2, $test_day, $test_year );
> >$link = "\t<LI><A
> >HREF=\"./recaps.php3?&filename=$file">$f_subj</A>\r";
> >$link_array = array( "date" => "$key", "link" =>
> >"$link", "id" => "$c" );
>
> $c is incremented each time an variable is put in so it's like the index key
> for me to use in the for() loop to print out the array later.
>
> There's probably some easier way to do this or even an easy function to do
> this, but I can't figure it out... any help would be great. Thanks!
I think this would do it:
//Untested code:
function linkcmp($link1, $link2){
$result = 0;
if ($link1['date'] < $link2['date']){
$result = -1;
}
elseif ($link1['date'] > $link2['date']){
$result = 1;
}
return $result;
}
usort($link_array, 'linkcmp');
--
Richard Lynch | If this was worth $$$ to you, buy a CD
US Customer Support Director | from one of the artists listed here:
Zend Technologies USA | http://www.L-I-E.com/artists.htm
http://www.zend.com | (this has nothing to do with Zend,
duh!)