Sunday, November 29, 2015

Ordinal Values in PHP

This sample program that I wrote in PHP as programming language to create the ordinal values. The code is very simple and easy to understand. I intended my work for beginners in PHP programming.

If you  have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing

<?php
echo "<br>";
echo "<font face='arial'>";
echo "<h2 align='center'> Ordinal Values in PHP </h2> </font>";
echo "<br>";
for ($a=1; $a<=100; $a++) {

 $mod100 = $a % 100;
 $mod10 = $a % 10;

if ($mod10 == 1 && $mod100 != 11) {

   $message= "st";

} else if  ($mod10 == 2 && $mod100 != 12) {
 $message="nd";
}
else if  ($mod10 == 3 && $mod100 != 13) {
$message= "rd";
} else {
 $message= "th";
 }


 echo "<font face='arial' size='5'>";
 echo " ".$a.$message."</font>";
}

?>

No comments:

Post a Comment