waynew Posted July 14, 2008 Share Posted July 14, 2008 Ok, this is another question altogether. I have a messed up array. Array ( [0] => 1151.519 [6] => 24345.6248 [5] => 186.456 [1] => 8177.1744 [4] => 10674.6675 [2] => 16434.037 [3] => 29104.1746 [7] => 5935.786 [8] => 10403.2978 [9] => 4444.859 ) How can I sort that array so that the indexes go from 1 to 9? Not jumbled? Link to comment https://forums.phpfreaks.com/topic/114654-solved-sort-by-index/ Share on other sites More sharing options...
rhodesa Posted July 14, 2008 Share Posted July 14, 2008 http://php.net/sort And did you trying finding this on your own at all before posting? Try searching the web at least once before asking a common question like this. Googling 'php array sort' would get you to the above page too.... http://www.google.com/search?q=php+array+sort also, if you are new to PHP, try going through this: http://devzone.zend.com/node/view/id/627 it's a great resource for beginners and covers pretty much every part of PHP Link to comment https://forums.phpfreaks.com/topic/114654-solved-sort-by-index/#findComment-589593 Share on other sites More sharing options...
waynew Posted July 14, 2008 Author Share Posted July 14, 2008 I have tried to search http://www.google.com/search?hl=en&q=php+sort+array+by+index+key&btnG=Search But every result tends to lean towards sorting alphabetical keys and not numerical ones. Will the same type of sort work? Link to comment https://forums.phpfreaks.com/topic/114654-solved-sort-by-index/#findComment-589596 Share on other sites More sharing options...
rhodesa Posted July 14, 2008 Share Posted July 14, 2008 Sorry, misread, for sorting by KEY it's ksort: http://us3.php.net/manual/en/function.ksort.php Link to comment https://forums.phpfreaks.com/topic/114654-solved-sort-by-index/#findComment-589599 Share on other sites More sharing options...
kenrbnsn Posted July 14, 2008 Share Posted July 14, 2008 Read the php manual about arrays and sorting. In your case you want ksort(). Ken Link to comment https://forums.phpfreaks.com/topic/114654-solved-sort-by-index/#findComment-589601 Share on other sites More sharing options...
waynew Posted July 14, 2008 Author Share Posted July 14, 2008 Thanks so much guys. That sorted out my problem. I had to use slice on the two arrays and the fact that the second one wasn't in order caused unpredictible things to happen. I've been at it for hours now. Thanks guys. Link to comment https://forums.phpfreaks.com/topic/114654-solved-sort-by-index/#findComment-589611 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.