Perad Posted October 7, 2008 Share Posted October 7, 2008 If I have a an array which as - $key => $value. - where key is a persons name and value is their age. What is the most efficient way to organise the array alphabetically by the key? Link to comment https://forums.phpfreaks.com/topic/127396-order-array-alphabetically/ Share on other sites More sharing options...
Orio Posted October 7, 2008 Share Posted October 7, 2008 Simple - ksort() <?php ksort($array); ?> Orio. Link to comment https://forums.phpfreaks.com/topic/127396-order-array-alphabetically/#findComment-658996 Share on other sites More sharing options...
aebstract Posted October 7, 2008 Share Posted October 7, 2008 ksort($array); foreach ($array as $key => $value) { echo "$key = $value\n"; } edit: Looks like I'm too slow Link to comment https://forums.phpfreaks.com/topic/127396-order-array-alphabetically/#findComment-658997 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.