Posted By

ajbatac on 01/17/08


Tagged

prefix


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

brent-man
adix
Priestd09


A function to add a prefix to numbers ex. 1st 2nd 3rd 4th 5th


 / Published in: PHP
 

  1. function ordinalize($number) {
  2. if (in_array(($number % 100),range(11,13))){
  3. return $number.'th';
  4. }else{
  5. switch (($number % 10)) {
  6. case 1:
  7. return $number.'st';
  8. break;
  9. case 2:
  10. return $number.'nd';
  11. break;
  12. case 3:
  13. return $number.'rd';
  14. default:
  15. return $number.'th';
  16. break;
  17. }
  18. }
  19. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: razel on February 6, 2008

thats called suffix not prefix :-/

You need to login to post a comment.