You are here: Re: sort string beginning at index? « All PHP « IT news, forums, messages
Re: sort string beginning at index?

Posted by NC on 09/29/05 21:44

Stan McCann wrote:
>
> I need some recommendations as to how to go about sorting a string not
> from the beginning of the string, but from a given index into the
> string. I am reading a data file into an array using file(), then
> looping through the string which contains fields seperated by |. Do I
> have to explode each individual record to sort them using
> array_multisort()? What I was hoping for was something like sort
> ($array, SORT_STRING, 15) where 15 is the index into the string to sort
> on instead of starting at 0.

// Untested
function sort_starting_at_index($array, $index) {
$temp = array();
$newarray = array();
foreach ($array as $key=>$value) {
$temp[$key] = substr($value, $index);
}
asort($temp, SORT_STRING);
foreach ($temp as $key=>$value) {
$newarray[] = $array[$key];
}
return $newarray;
}

Cheers,
NC

 

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

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