note 20915 added to ref.strings
| From: | captainbajoo at juno dot com | Date: | Sun, 21 Apr 2002 21:09:37 +0000 |
| Subject: | note 20915 added to ref.strings | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-29661@lists.php.net to get a copy of this message | ||
This is a more compact function to get a numeric adjective. No idea if it's faster than the
other "nth" function here (though probably is, since "th" is more likely to
occur), but the code is definitely shorter.
Assumes integer input. Returns a string.
function getNth ($n) {
$qn = (int) (($n%100) / 10);
$rn = $n % 10;
$suffix = "th";
if ($qn != 1) {
switch ($rn) {
case 1: $suffix = "st"; break;
case 2: $suffix = "nd"; break;
case 3: $suffix = "rd"; break;
}
}
return $n . $suffix;
}
--
http://www.php.net/manual/en/ref.strings.php
http://master.php.net/manage/user-notes.php?action=edit+20915
http://master.php.net/manage/user-notes.php?action=delete+20915
http://master.php.net/manage/user-notes.php?action=reject+20915