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 :) Quote 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 ;) Quote 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. Quote 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 Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.