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. Link to comment https://forums.phpfreaks.com/topic/47051-solved-natsort-failing-meh/ 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); Link to comment https://forums.phpfreaks.com/topic/47051-solved-natsort-failing-meh/#findComment-229481 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? Link to comment https://forums.phpfreaks.com/topic/47051-solved-natsort-failing-meh/#findComment-229484 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 Link to comment https://forums.phpfreaks.com/topic/47051-solved-natsort-failing-meh/#findComment-229488 Share on other sites More sharing options...
StormTheGates Posted April 15, 2007 Author Share Posted April 15, 2007 Thank you kindly good sir. Link to comment https://forums.phpfreaks.com/topic/47051-solved-natsort-failing-meh/#findComment-229492 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.