diff --git a/src/Illuminate/Support/Str.php b/src/Illuminate/Support/Str.php index c4c911d8a75f..f80f05a72733 100644 --- a/src/Illuminate/Support/Str.php +++ b/src/Illuminate/Support/Str.php @@ -2087,4 +2087,26 @@ public static function flushCache() static::$camelCache = []; static::$studlyCache = []; } + + /** + * Get the ordinal suffix for a given number. + * + * @param int $number + * @return string + */ + public static function ordinal(int $number) + { + if (! in_array($number % 100, [11, 12, 13])) { + switch ($number % 10) { + case 1: + return $number . 'st'; + case 2: + return $number . 'nd'; + case 3: + return $number . 'rd'; + } + } + + return $number . 'th'; + } }