note 77609 added to ref.math
| From: | ddarjany at yahoo dot com | Date: | Wed, 05 Sep 2007 17:25:15 +0000 |
| Subject: | note 77609 added to ref.math | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-130218@lists.php.net to get a copy of this message | ||
Tim's fix of Evan's ordinal function causes another problem, it no longer works for number
above 100. (E.g. it returns 111st instead of 111th).
Here is a further modified version which should work for all numbers.
<?PHP
function ordinal($cardinal) {
$cardinal = (int)$cardinal;
$digit = substr($cardinal, -1, 1);
if ($cardinal <100) $tens = round($cardinal/10);
else $tens = substr($cardinal, -2, 1);
if($tens == 1) {
return $cardinal.'th';
}
switch($digit) {
case 1:
return $cardinal.'st';
case 2:
return $cardinal.'nd';
case 3:
return $cardinal.'rd';
default:
return $cardinal.'th';
}
}
?>
----
Server IP: 208.69.120.35
Probable Submitter: 207.233.67.6
----
Manual Page -- http://www.php.net/manual/en/ref.math.php
Edit -- https://master.php.net/note/edit/77609
Del: integrated -- https://master.php.net/note/delete/77609/integrated
Del: useless -- https://master.php.net/note/delete/77609/useless
Del: bad code -- https://master.php.net/note/delete/77609/bad+code
Del: spam -- https://master.php.net/note/delete/77609/spam
Del: non-english -- https://master.php.net/note/delete/77609/non-english
Del: in docs -- https://master.php.net/note/delete/77609/in+docs
Del: other reasons-- https://master.php.net/note/delete/77609
Reject -- https://master.php.net/note/reject/77609
Search -- https://master.php.net/manage/user-notes.php