noobh Posted November 14, 2007 Share Posted November 14, 2007 ok this is the code <?php $array = array('one'=>'orange','two'=>'banana','three'=>'grapes','four'=>'lemon','five'=>'apple'); sort($array); foreach($array as $key => $val){ echo $key . "=>" . $val . "<br />"; } This is the output the value are already sorted 0=>apple 1=>banana 2=>grapes 3=>lemon 4=>orange But this is the output that i like five=>apple two=>banana three=>grapes four=>lemon one=>orange the value are sorted and the key are still remain!! i mean the key of apple is still five and not become 0 any idea thanks in advance Link to comment https://forums.phpfreaks.com/topic/77288-solved-how-to-sort-array/ Share on other sites More sharing options...
trq Posted November 14, 2007 Share Posted November 14, 2007 <?php $array = array('one'=>'orange','two'=>'banana','three'=>'grapes','four'=>'lemon','five'=>'apple'); asort($array); foreach($array as $key => $val){ echo $key . "=>" . $val; } ?> Link to comment https://forums.phpfreaks.com/topic/77288-solved-how-to-sort-array/#findComment-391300 Share on other sites More sharing options...
noobh Posted November 14, 2007 Author Share Posted November 14, 2007 Thanks a lot bro i spend an hours for searching for this king of function anyway thanks again Link to comment https://forums.phpfreaks.com/topic/77288-solved-how-to-sort-array/#findComment-391346 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.