Wta Module 5
Wta Module 5
Wta Module 5
<?php
$marks = 40;
if ($marks>=60)
{
$grade = "First Division";
}
else if($marks>=45)
{
$grade = "Second Division";
}
else if($marks>=33)
{
$grade = "Third Division";
}
else
{
$grade = "Fail";
}
OUTPUT:
Student grade: Third Division
<?php
function factorial($number) {
if ($number < 2) {
return 1;
} else {
return ($number * factorial($number-1));
}
}
echo factorial(4);
?>
OUTPUT:
24
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<h3>Chess Board using Nested For Loop</h3>
<table width="270px" cellspacing="0px" cellpadding="0px" border="1px">
<!-- cell 270px wide (8 columns x 60px) -->
<?php
for($row=1;$row<=8;$row++)
{
echo "<tr>";
for($col=1;$col<=8;$col++)
{
$total=$row+$col;
if($total%2==0)
{
echo "<td height=30px width=30px bgcolor=#FFFFFF></td>";
}
else
{
echo "<td height=30px width=30px bgcolor=#000000></td>";
}
}
echo "</tr>";
}
?>
</table>
</body>
</html>
OUTPUT:
4.Write a PHP script to create enumerated array and associative array and display
the contents using foreach loop.
<?php
$flexiple = array("Hire", "top", "freelance", "developers");
OUTPUT:
Hire
top
freelance
developers
name: Eric
email: Eric@gmail.com
age: 22
gender: male
5.Demonstrate how to post data from HTML to PHP using php code.
<!DOCTYPE HTML>
<html>
<body>
</body>
</html>
<html>
<body>
In M5a.html
Welcome sanjana
Your email address is: sanjana@gmail.com
function associative(){
$arr=array("a"=>"1","b"=>"2","c"=>"3","d"=>"4");
echo "<h2>Associative array inside function<br></h2>";
foreach($arr as $x=>$y){
echo $x." => ".$y.", ";
}
echo "<br>";
return $arr;
}
$arr1=associative();
echo "<h2>Associative array in main<br></h2>";
echo "<table><tr><th>Key</th><th>Value</th></tr>";
foreach($arr1 as $x=>$y){
echo "<tr><td>".$x."</td><td>".$y."</td></tr>";
}
echo "</table>"
?>
</body>
</html>