PHP 1st, 2nd, 3rd, 4th, 5th, 6th – PHP Add Ordinal Number Suffix - Comment Page: 2

This is simple function to add English ordinal number suffix after normal number. Function takes number as a parameter and returns number with suffix, like: 1st, 2nd, 3rd, 4th, 5th, 6th... This is example table of ordinal numbers 1 to 100 1st 2nd 3rd 4th 5th 6th 7th 8th 9th ...

26 comments on “PHP 1st, 2nd, 3rd, 4th, 5th, 6th – PHP Add Ordinal Number Suffix - Comment Page: 2

1 2
    1. Did the job for me – exactly what I was looking for. Thanks guys

      Reply
    2. Thanks you, it’s really good

      Reply
    3. Thanks you,
      its working fine.

      Reply
    4. Thanks for the useful function. I wrote a functionally similar (but horribly ugly) function to accomplish this many years ago, but yours is by far superior, and I’ve replaced my function with yours in my snippet library. Cheers!

      Reply
    5. You have recreated functionality that already exists in php since 5.3

      $nf = new NumberFormatter(‘en_US’, NumberFormatter::ORDINAL);

      for ($i = 1; $i format($i). “\r\n”;
      }

      Reply
      • Hi Ryan,

        This code/post has been published in 2010, when PHP 5.3 was brand new and not so widely used. And I’m not sure is your code truncated or something, but it’s not working.

        Reply
1 2

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Close