You are here: Re: print order of assoctive array « PHP Programming Language « IT news, forums, messages
Re: print order of assoctive array

Posted by Erwin Moller on 10/30/89 11:33

pauld wrote:

>
>
> Ive got a series of 2 dimensional associative arrays
> while(list($key, $val) = each ($results))
> {
> {foreach($val as $i=>$v)
> print "$i = $v";
> }
> }
>
>
> but i want to define the order that the various $i's are printed in
> (not numerical/alphabetically)
>
> arrays named
> "key1_sorted_order" = keys in the order to be printed
> "key2_sorted_order"
>
> ive been experimeting with
>
> while(list($key, $val) = each ($results))
> {
> {foreach($val as $i=>$v)
> $ks=$i.'_sorted_order';
> ($cntr=0;cntr<count($ks);$cntr++ )
> { print [$ks[$cntr]] =$results[$val[$ks[$cntr]]]
> }
> }
> }
>
> anyone able to help me out ?

Hi,

I just wrote a similar routine yesterday. :-)
Try this:

Move every element in your array to a new array, using an assoc-index of
your choice, and thus defining the ordering.
ksort ($newarray)

Works like a charm.

If the default ksort is not to your liking, use uksort.

Good luck

Regards,
Erwin Moller

 

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

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