note 89235 deleted from function.number-format by cmb
| From: | cmb@php.net | Date: | Tue, 13 Nov 2018 11:48:00 +0000 |
| Subject: | note 89235 deleted from function.number-format by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-209698@lists.php.net to get a copy of this message | ||
Note Submitter: ben at last dot fm
----
Writing a function to get English ordinals for numbers is a problem every computer science student
will face. Here's my solution - nice, short and simple:
<?php
function st($i) {
switch( floor($i/10) % 10 ) {
default:
switch( $i % 10 ) {
case 1: return 'st';
case 2: return 'nd';
case 3: return 'rd';
}
case 1:
}
return 'th';
}
?>