[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

RE: [PROGRAMMERING] PHP: ændre rækkefølgen på et associativt array



> Du har ingen mulighed for at bestemme placering af et 
> element, da placeringen bestemmes af hash funktionen.

Det er faktisk ikke rigtigt. I PHP vil f.eks. en foreach-løkke vise dem i
den rækkefølge, de er blevet tilføjet array'et i - ikke sorteret efter deres
nøgle (hvilket ville være det mest naturlige...)

Men for at svare på Peters spørgsmål: Den eneste måde, jeg har kunne finde
ud af at ændre i rækkefølgen, er ved:
1) Lave et nyt array hvor du sætter dem i den rækkefølge, du vil have dem ud
på.
2) Hvis det bare er nogle få elementer, du vil have tilsidst, kan du bruge
$tmp = $ditarray['dinnøgle]; unset($ditarray['dinnøgle]);
$ditarray['dinnøgle'] = $tmp;

Meget lidt elegant!

Mange hilsner

Lars



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2006-11-01, 02:01 CET [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *