You are here: Re: sorting an array.. need help « PHP Programming Language « IT news, forums, messages
Re: sorting an array.. need help

Posted by Jerry Stuckle on 01/30/06 12:45

namemattersnot@msn.com wrote:
> re,
>
> i've have the following array:
>
> files['name'][1]
> ['size'][1]
> ['time'][1]
> files['name'][2]
> ['size'][2]
> ['mtime'][2]
> ..etc.
>
> how do I sort this array according to "time" index? so that, for
> example, files['name'][0] would give "my_file.txt" that was last
> created?
>
> thank you in advance!
>

(I hope the mtime in your second element is a typo...)

Someting like (not tested):

<?php
function cmp($a, $b)
{
// Could also be done with ternary operator.
// But this is easier to understand

if ($a['time'] > $b['time'])
return 1;
else
if ($a['time' == $b['time'])
return 0;
else
return -1;
}


uksort($files, "cmp");

}
?>


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

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

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