note 20915 deleted from ref.strings by tomsommer

From: Date: Wed, 15 Sep 2004 20:49:00 +0000
Subject: note 20915 deleted from ref.strings by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-76796@lists.php.net to get a copy of this message
Note Submitter: captainbajoo at juno dot com ---- 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; }

« previous php.notes (#76796) next »