Code:

/** * Get the ordinal suffix of an int (e.g. st, nd, rd, th) * @param int $n * @return string $suffix */ function ordinal_suffix( $n ) { switch ( $n % 100 ) { case '11': case '12': case '13': return 'th'; } switch ( $n % 10 ) { case '1': return 'st'; case '2': return 'nd'; case '3': return 'rd'; default: return 'th'; } } // Usage Example: foreach ( range( 0, 24 ) as $n ) { echo $n . ordinal_suffix( $n ) . ' '; }

Output:

0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th