EchoFool Posted June 15, 2009 Share Posted June 15, 2009 Does any one know of a function which converts numbers to rank? like below: 1 = 1st 2 = 2nd 3 = 3rd Etc Or am i going to have to make my own function for something like this ? Link to comment https://forums.phpfreaks.com/topic/162200-solved-function-to-convert-number-to-ranking/ Share on other sites More sharing options...
rhodesa Posted June 15, 2009 Share Posted June 15, 2009 http://www.phpsnips.com/snippet.php?id=37 Link to comment https://forums.phpfreaks.com/topic/162200-solved-function-to-convert-number-to-ranking/#findComment-855974 Share on other sites More sharing options...
Alex Posted June 15, 2009 Share Posted June 15, 2009 Well, you could just hijack the date function function postFix($number) { $faketime = ($number * 86400) + 1230768000; return date("S", $faketime); } $num = 5; echo $num . postFix($num); Output: 5th Edit: Nevermind, this is stupid since it will only work for 1-31. Link to comment https://forums.phpfreaks.com/topic/162200-solved-function-to-convert-number-to-ranking/#findComment-855975 Share on other sites More sharing options...
EchoFool Posted June 15, 2009 Author Share Posted June 15, 2009 Good find rhodesa, thanks for trying too AlexWD Link to comment https://forums.phpfreaks.com/topic/162200-solved-function-to-convert-number-to-ranking/#findComment-855977 Share on other sites More sharing options...
Alex Posted June 15, 2009 Share Posted June 15, 2009 Oh, just FYI you can make it work with my idea. function postFix($number) { $number = ($number > 31) ? (substr($number, -1, 1)) : $number; if($number == 0) $number = 4; $faketime = ($number * 86400) + 1230768000; return date("S", $faketime); } for($num = 1;$num < 100;$num++) { echo $num . postFix($num) . '<br />'; } Accurate, as far as I know. Link to comment https://forums.phpfreaks.com/topic/162200-solved-function-to-convert-number-to-ranking/#findComment-855982 Share on other sites More sharing options...
rhodesa Posted June 15, 2009 Share Posted June 15, 2009 @AlexWD - it works, but the snippet in the link i posted runs 35 times faster Link to comment https://forums.phpfreaks.com/topic/162200-solved-function-to-convert-number-to-ranking/#findComment-856147 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.