Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6110161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:29:04+00:00 2026-05-23T14:29:04+00:00

Possible Duplicate: Display numbers with ordinal suffix in PHP I think they are called

  • 0

Possible Duplicate:
Display numbers with ordinal suffix in PHP

I think they are called Ordinal suffixes.

Have seen examples for dates…

But just wondered if there was some php that can spew out the suffix dependant on number.

Example: we are spewing out the leaderboard score of our users.

So member ranked number 1. we wish to echo: 1’st
and member ranked 847. we want to spew out 847’th

etc etc

I cannot give example, as the numbers are rendered on page via our dB

Just wondered if there was some sort of code snippet, that could add automagically ‘th or ‘st or ‘rd to the appropriate number.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:29:04+00:00Added an answer on May 23, 2026 at 2:29 pm

    I don’t know of any built-ins that do this, but this should work:

    function ordinal_suffix($num){
        $num = $num % 100; // protect against large numbers
        if($num < 11 || $num > 13){
             switch($num % 10){
                case 1: return 'st';
                case 2: return 'nd';
                case 3: return 'rd';
            }
        }
        return 'th';
    }
    

    (note 11, 12 and 13 are special cases – 11th, 12th, 13th vs 11st…)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: php display number with ordinal suffix I'm attempting to add ordinal contractions
Possible Duplicate: How to find number of days between two dates using php I'm
Possible Duplicate: How to display row numbers in a ListView? Currently I am using
Possible Duplicate: Is there a tool that can display a SVN repository visually (
Possible Duplicate: How does the Google Did you mean? Algorithm work? Suppose you have
Possible Duplicate: NSNumberFormatter and ‘th’ ‘st’ ‘nd’ ‘rd’ (ordinal) number endings Hello, I'm building
Possible Duplicates: Display possible combinations of string algorithm that will take numbers or words
Possible Duplicate: Dealing with accuracy problems in floating-point numbers I was quite surprised why
Possible Duplicate: Why doesn’t VS 2008 display extension methods in Intellisense for String class
Possible Duplicate: Datetime vs Timestamp? I have a Mysql table, which has a column

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.