StormTheGates Posted April 15, 2007 Share Posted April 15, 2007 Can someone explain to me why this dosnt work? $cards = array("2h", "4d", "1s", "5c", "8d"); natsort($cards); echo "$cards[0]-$cards[1]-$cards[2]-$cards[3]"; You would think that it would sort them into 1s-2h-4d-5c But it dosnt, it dosnt seem to sort at all. It just prints out 2h-4d-1s-5c Any ideas why? Its driving me insane. Quote Link to comment Share on other sites More sharing options...
Guest prozente Posted April 15, 2007 Share Posted April 15, 2007 It's working just as stated. From the PHP manual "This function implements a sort algorithm that orders alphanumeric strings in the way a human being would while maintaining key/value associations." print_r ($cards); and you will see it did sort, it doesn't reindex. If you want to re-index you can use array_values $cards = array_values($cards); Quote Link to comment Share on other sites More sharing options...
StormTheGates Posted April 15, 2007 Author Share Posted April 15, 2007 Ahhhhhhh I see, is there any way to get it to reindex? Quote Link to comment Share on other sites More sharing options...
Guest prozente Posted April 15, 2007 Share Posted April 15, 2007 I edited and added that to my post before you replied Quote Link to comment Share on other sites More sharing options...
StormTheGates Posted April 15, 2007 Author Share Posted April 15, 2007 Thank you kindly good sir. Quote Link to comment 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.