[Typo3-dev] Splitting array acording to alphabet

Michael Scharkow mscharkow at gmx.net
Fri Jun 17 11:42:07 CEST 2005


Georg Ringer wrote:
> Hello,
> 
> now I have really got a hard nut to crack:
> I havw got a muldidimensional array which looks like this:
> [count] [last name] [first name] [id] which is sorted by last name.
> 
> Now I want to show before every third alphabetic caracter a varible.

Another approach: Prepare an empty assoc. array that looks like this

$indexed['a'] = array()
$indexed['b'] = array()

then loop through all elements of your original array, and do

array_push($indexed[strtolower($yourarray[1]{0})], $yourarray)

With this you get a simple index, from which you can extract the names
starting with X, merge them, sort them, etc.

Just an idea, I'm sure there's a more elegant solution.

Greetings,
Michael




More information about the TYPO3-dev mailing list