note 42083 added to function.is-numeric
| From: | renimarnospamatnospamyahoodotcom at rn2 dot php dot net | Date: | Mon, 03 May 2004 04:54:58 +0000 |
| Subject: | note 42083 added to function.is-numeric | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-69122@lists.php.net to get a copy of this message | ||
A little function to ordinalize numbers using is_numeric() and accounting for the numbers in the
teens.
<?php
function ordinalize($num) {
if (!is_numeric($num))
return $num;
if ($num >= 11 and $num <= 19)
return $num."th";
elseif ( $num % 10 == 1 )
return $num."st";
elseif ( $num % 10 == 2 )
return $num."nd";
elseif ( $num % 10 == 3 )
return $num."rd";
else
return $num."th";
}
// Demo
for ($i=1; $i<=25; $i++) {
print ordinalize($i) . " ";
}
// The loop returns:
// 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th
// 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd
// 23rd 24th 25th
?>
----
Manual Page -- http://www.php.net/manual/en/function.is-numeric.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+42083
Delete -- http://master.php.net/manage/user-notes.php?action=delete+42083&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+42083&report=yes
Search -- http://master.php.net/manage/user-notes.php