Format Ordinal

Convert a number to its ordinal form (1st, 2nd, 3rd, etc.).

Code

Utilities
$suffixes = ['th', 'st', 'nd', 'rd'];
$v = $num % 100;
$suffix = ($v >= 11 && $v <= 13) ? 'th' : ($suffixes[$v % 10] ?? 'th');
$num . $suffix;

Parameters

Number to convert.

Server

More PHP Snippets