View Full Version : add_ordinals in PHP

04-12-2004, 07:30 PM

A beautiful javascript function as the result of the best minds on this forum coming together, but I'm trying to rewrite it in PHP. Maybe because I don't fully understand the Javascript in it, but this function always seems to return 'th'.
function add_ordinals($num){
$ords = array ( "th","st","nd","rd" );
$num . $ords[(!((($num=this%10) >3) || (floor(this%100/10)==1))) * $num];
}Any help in debugging is appreciated.

04-12-2004, 08:42 PM
how about this? (ain't english so not to fluent in ordinals)

function toOrdinal($num)
$ords = array ( "st","nd","rd" ,"th");
return $num .$ords[(($num%10<4)&&($num%10>0)&&(floor($num%100/10)!=1))?($num%10-1):3];

04-12-2004, 10:30 PM
a ord on numbers using date function

foreach($a as $b)
echo $b.$ord."<br>";

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum