php - Adding Ordinal Contractions to $i -
possible duplicate:
php display number ordinal suffix
i'm attempting add ordinal contractions i.e.(st/nd/rd/th) increment.
somehow need last digit of $i test against if statements...
here code far:
$i = 1; while($i < 101 ){ if($i == 1){$o_c = "st";}else{$o_c = "th";} if($i == 2){$o_c = "nd";} if($i == 3){$o_c = "rd";} echo $i.$o_c."<br/>"; $i++; }
you can use modulus (%) operator remainder when dividing 10.
$i = 1; while($i < 101 ){ $remainder = $i % 10; if($remainder == 1){$o_c = "st";}else{$o_c = "th";} if($remainder == 2){$o_c = "nd";} if($remainder == 3){$o_c = "rd";} echo $i.$o_c."<br/>"; $i++; }
Comments
Post a Comment