Whats the most elegant way to rearrange an associative array?

Posted by Fletcher Moore on Stack Overflow See other posts from Stack Overflow or by Fletcher Moore
Published on 2010-04-22T20:40:49Z Indexed on 2010/04/22 20:43 UTC
Read the original article Hit count: 266

Filed under:
|
|

Suppose you have an associative array

$hash['Fruit'] = 'Apple';
$hash['Name'] = 'Jeff';
$hash['Car'] = 'Ford';

and you cannot change the order in which these variables are created. So Car is always added to the array after Name, etc. What's the prettiest way to add/move Car to the beginning of the associative array instead of the end (default)?

© Stack Overflow or respective owner

Related posts about php

Related posts about array