t_machine Posted January 27, 2007 Share Posted January 27, 2007 hi, I am having a little problem sorting the following array example$foo = array('banana'=>'2', 'apple'=>'5', 'grape'=>'8');How can I sort that array so "apple" shows first then "banana"... before using the foreach ?Thanks :) Link to comment https://forums.phpfreaks.com/topic/35913-solved-how-to-sort-alphabetically-in-array/ Share on other sites More sharing options...
HuggieBear Posted January 27, 2007 Share Posted January 27, 2007 You can use ksort() to sort an array on it's keys.[code]<?php$foo = array('banana'=>'2', 'apple'=>'5', 'grape'=>'8');ksort($foo);?>[/code]RegardsHuggie ;) Link to comment https://forums.phpfreaks.com/topic/35913-solved-how-to-sort-alphabetically-in-array/#findComment-170287 Share on other sites More sharing options...
t_machine Posted January 27, 2007 Author Share Posted January 27, 2007 Thank you very much :) works perfectly now. Link to comment https://forums.phpfreaks.com/topic/35913-solved-how-to-sort-alphabetically-in-array/#findComment-170290 Share on other sites More sharing options...
HuggieBear Posted January 27, 2007 Share Posted January 27, 2007 No problem, don't forget to use the 'Solved' mod to mark the topic as solved.RegardsHuggie Link to comment https://forums.phpfreaks.com/topic/35913-solved-how-to-sort-alphabetically-in-array/#findComment-170297 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.