Return to Snippet

Revision: 49428
at July 21, 2011 20:47 by theworldofdan


Initial Code
<?php
function ordinal($cdnl){
    $test_c = abs($cdnl) % 10;
    $ext = ((abs($cdnl) %100 < 21 && abs($cdnl) %100 > 4) ? 'th'
            : (($test_c < 4) ? ($test_c < 3) ? ($test_c < 2) ? ($test_c < 1)
            ? 'th' : 'st' : 'nd' : 'rd' : 'th'));
    return $cdnl.$ext;
} 
for($i=1;$i<100;$i++){
    echo ordinal($i).'<br>';
}

Initial URL
http://phpsnips.com/snippet.php?id=37

Initial Description

                                

Initial Title
Add (th, st, nd, rd, th) to the end of a number

Initial Tags

                                

Initial Language
PHP