Skip to content

Instantly share code, notes, and snippets.

@pierreburel
Forked from kbanman/modifier.ordinal.php
Created March 18, 2022 18:04
Show Gist options
  • Save pierreburel/b6f9c5fb317a2504b35d140b928e6887 to your computer and use it in GitHub Desktop.
Save pierreburel/b6f9c5fb317a2504b35d140b928e6887 to your computer and use it in GitHub Desktop.
Smarty ordinal modifier plugin
<?php
/**
* Gets the ordinal for a number
*
* @param integer $number
* @return string
*/
function smarty_modifier_ordinal($number)
{
$number = intval($number);
if (!in_array(($number % 100), array(11, 12, 13))) {
switch ($number % 10) {
case 1: return $number . 'st';
case 2: return $number . 'nd';
case 3: return $number . 'rd';
}
}
return $number . 'th';
}
@pierreburel
Copy link
Author

This one doesn't show 12nd like the original did.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment