Skip to content

Instantly share code, notes, and snippets.

@softon
Created January 11, 2016 05:00
Show Gist options
  • Save softon/2b89990d5836d9b67a72 to your computer and use it in GitHub Desktop.
Save softon/2b89990d5836d9b67a72 to your computer and use it in GitHub Desktop.
A simple function to return the ordinal of any number
<?php
/**
* A simple function to return the ordinal of any number
* E.g: number = 1 => Ordinal = st
* E.g: number = 23 => Ordinal = rd
*
* @param int $number
* @return string
*/
function getOrdinal($number){
$n = $number%10;
switch($n){
case 1:
return 'st';
case 2:
return 'nd';
case 3:
return 'rd';
default:
return 'th';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment