StormTheGates Posted April 13, 2007 Share Posted April 13, 2007 Hello everyone. I am aware of the sort() function, however its not doing what I want it to do. I have an array for cards, and need to sort them. For instance I have this array: array("1s","4d","13h","7d","8c"); The problem is that when it sorts it sees 13 lower than 1. Or it notices the 1 before anything so I get a sort like this 13h 1s 4d 7d 8c When I really need this 1s 4d 7d 8c 13h Any ideas how this could be achieved? Thanks Link to comment https://forums.phpfreaks.com/topic/46881-sorting-arrays/ Share on other sites More sharing options...
StormTheGates Posted April 13, 2007 Author Share Posted April 13, 2007 Ah I figured it out myself. For future reference to anyone having this problem, I believe that natsort() Works for sorting naturally . Link to comment https://forums.phpfreaks.com/topic/46881-sorting-arrays/#findComment-228557 Share on other sites More sharing options...
taith Posted April 13, 2007 Share Posted April 13, 2007 change it so its like this... array("01s","04d","13h","07d","08c"); which would sort to... 01s 04d 07d 08c 13h then in your function(s) just put if($string{0}=="0") $string=substr($string,1); or whatnot :-) Link to comment https://forums.phpfreaks.com/topic/46881-sorting-arrays/#findComment-228558 Share on other sites More sharing options...
MadTechie Posted April 13, 2007 Share Posted April 13, 2007 <?php $X = array("1s","4d","13h","7d","8c"); print_r($X); natsort($X); print_r($X); ?> D'oh Link to comment https://forums.phpfreaks.com/topic/46881-sorting-arrays/#findComment-228559 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.