note 103537 modified in ref.math by danbrown

From: Date: Tue, 19 Apr 2011 14:57:03 +0000
Subject: note 103537 modified in ref.math by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-178973@lists.php.net to get a copy of this message
Here's a simple way way to convert a number to an ordinal number I created: $i == the number to convert. Put this inside a for loop if you need to populate an array. <?php // change increment variable to ordinal number. $n1 = $i % 100; //first remove all but the last two digits $n2 = ($n1 < 20 ? $1 : $i % 10; //remove all but last digit unless the number is in the teens, which all should be 'th' //$n is now used to determine the suffix. $ord = ($n2==1 ? $i.'st' : ( ($n2==2 ? $i.'nd' : ($n2==3 ? $i.'rd' : $i.'th') ) ) ) ?> --was-- Here's a simple way way to convert a number to an ordinal number I created: $i == the number to convert. Put this inside a for loop if you need to populate an array. // change increment variable to ordinal number. $n1 = $i % 100; //first remove all but the last two digits $n2 = ($n1 < 20 ? $1 : $i % 10; //remove all but last digit unless the number is in the teens, which all should be 'th' //$n is now used to determine the suffix. $ord = ($n2==1 ? $i.'st' : ( ($n2==2 ? $i.'nd' : ($n2==3 ? $i.'rd' : $i.'th') ) ) ) http://php.net/manual/en/ref.math.php

« previous php.notes (#178973) next »