You are here: Re: sort based on substring « PHP Programming Language « IT news, forums, messages
Re: sort based on substring

Posted by Rik Wasmus on 01/22/08 17:28

On Tue, 22 Jan 2008 18:04:31 +0100, brechmos <brechmos@gmail.com> wrote:=


> A bit of a dumb question. I have an array of directories and would
> like to sort the array based on the third directory element...
>
> e.g., from...
>
> here/there/200801/everywhere
> here/there/200803/everywhere2
> here/there/200802/everywhere3
>
> to...
>
> here/there/200801/everywhere
> here/there/200802/everywhere2
> here/there/200803/everywhere3
>
> I can think of lots of unelegant ways, is there an elegant one? (few
> lines of code?)

function _mysort($a,$b){
$a_array =3D explode('/',$a);
$asorter =3D isset($a_array[2]) ? $a_array[2] : '';
$b_array =3D explode('/',$b);
$bsorter =3D isset($b_array[2]) ? $b_array[2] : '';
return strcmp($asorter,$bsorter);
}
usort($array,'_mysort');

-- =

Rik Wasmus

 

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

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