note 67510 added to ref.math
| From: | marasek dot SPAMLESSattelton dot de at osu1 dot php dot net | Date: | Thu, 08 Jun 2006 12:23:15 +0000 |
| Subject: | note 67510 added to ref.math | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-113824@lists.php.net to get a copy of this message | ||
I could not resist to do a simpler version of the ordinal function:
<?php
function ordinal($num)
{
$num = (int)$num;
$digit = substr($num, -1, 1);
$ord = "th";
switch($digit)
{
case 1: $ord = "st"; break;
case 2: $ord = "nd"; break;
case 3: $ord = "rd"; break;
break;
}
return $num.$ord;
}
?>
One could replace the typecast with
<?php
if($num===NULL or $num==="")
{return NULL;}
?>
to get an empty result instead of "0th" in case $num is empty too.
----
Server IP: 212.124.37.9
Probable Submitter: 212.223.3.162
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/ref.math.php
Edit -- http://master.php.net/note/edit/67510
Del: integrated -- http://master.php.net/note/delete/67510/integrated
Del: useless -- http://master.php.net/note/delete/67510/useless
Del: bad code -- http://master.php.net/note/delete/67510/bad+code
Del: spam -- http://master.php.net/note/delete/67510/spam
Del: non-english -- http://master.php.net/note/delete/67510/non-english
Del: in docs -- http://master.php.net/note/delete/67510/in+docs
Del: other reasons-- http://master.php.net/note/delete/67510
Reject -- http://master.php.net/note/reject/67510
Search -- http://master.php.net/manage/user-notes.php