WBP File
WBP File
WBP File
NESTED IF
if($grade>=90)
{
echo"Congratulations! You got an A.";
}
elseif($grade>=80)
{
echo"Congratulations! You got a B.";
}
elseif($grade>=70)
{
echo"Good!You got a C.";
}
}
else
{
echo"Sorry you have failed.";
}
?>
</body>
</html>
1
OUTPUT
2
PROGRAM 2
TYPE CASTING
//float
$v2=6.99;
echo"<br>Original float:<br>";
var_dump($v2);
echo "<p>Type:" .gettype($v2)."</p>";
//string
$var="Hello,PHP!";
echo"<br>Original string:<br>";
var_dump($var);
echo "<p>Type:" .gettype($var)."</p>";
//Boolean
$v3="true";
echo"<br>Original boolean:<br>";
var_dump($v3);
3
echo "<p>Type:" .gettype($v3)."</p>";
//array
$v3="true";
echo"<br>Original boolean:<br>";
var_dump($v3);
echo "<p>Type:" .gettype($v3)."</p>";
?>
</h1>
</body>
</html>
4
OUTPUT
5
PROGRAM 3
SWITCH CASE
Aim: Write a program to show the usage switch case using menu driven program
Program:
<html><body>
6
OUTPUT
7
PROGRAM 4
For/While/Do While Loop
Aim: Write a program to show the usage of for/while/do while loop coding
Program:
<?php
echo("while_loop=");
echo("<br>");
$x=1;
while($x<=5)
{
echo"The number is:$x"."<br>";
$x++;
}
echo("<br>");
echo("do_while_loop=");
echo("<br>");
$y=6;
do{
echo"The number is:$y"."<br>";
$y++;
} while($y<=10);
echo("<br>");
echo("for_loop=");
echo("<br>");
for ($z=11;$z<=15;$z++)
{
echo"The number is:$z"."<br>";
}
?>
8
OUTPUT
9
PROGRAM 5
ASSOCIATIVE ARRAY
10
OUTPUT
11
PROGRAM 6
MULTI-DIMENSIONAL ARRAY
12
OUTPUT
13
PROGRAM 7
SORTING
$a2=array(6,8,3,2,9);
rsort($a2);
echo("rsort=");
print_r($a2)."<br>";
echo("<br>");
echo("<br>");
$a3=array("sonam"=>"45","ram"=>"25","priya"=>"11","ira"=>"56");
asort($a3);
echo("asort=");
print_r($a3)."<br>";
echo("<br>");
echo("<br>");
$a4=array("45"=>"sonam","25"=>"ram","11"=>"priya","56"=>"ira");
ksort($a4);
echo("ksort=");
print_r($a4)."<br>";
echo("<br>");
echo("<br>");
?>
14
OUTPUT
15
PROGRAM 8
ARRAY FUNCTIONS
echo "<br><br><br>";
echo "<b> array_slice </b><br>";
$array = array(1, 2, 3, 4, 5);
$slicedArray = array_slice($array, 2, 3);
print_r($slicedArray);
echo "<br><br><br>";
16
// Display each chunk
foreach ($chunks as $ch) {
print_r($ch);
echo "<br>";
}
?>
</body>
</html>
17
OUTPUT
18
PROGRAM 9
USER DEFINED FUNCTIONS
<?php
function rect($l,$b)
{
echo "AREA OF RECTANGLE IS: ".$l*$b."<br>";
}
rect(4,5);
function cir($r)
{
echo "AREA OF CIRCLE IS: ".(22/7)*$r*$r."<br>";
}
cir(7);
?>
19
OUTPUT
20
PROGRAM 10
Program Controlling Functions
Aim : Write a program that Passes control to another page (include, require, exit and die
functions)
Program: EXIT OR DIE
<?php
$age = 1;
if ($age < 2) {
exit("Age must be more than 2");
// This line will not be executed because exit terminates the script
echo "Thank you for running the program";
} else {
echo "Your age is " . $age;
}
?>
REQUIRE (sample.php)
<html>
<body bgcolor="Lavender">
<h1> Example for REQUIRE </h1>
<?php
$a=10;
$b=20;
?>
</body>
</html>
REQUIRE CODE
<html>
<body>
<?php
require 'sam.php';
echo "<br>";
echo "Program is working with a value $a and b value $b <br>";
echo "Addition of 2 numbers is " . ($a + $b);
?>
</body>
</html>
21
INCLUDE
<html>
<body bgcolor="Lavender">
<h1>INCLUDE</h1>
</body>
</html>
INCLUDE CODE
<html>
<body>
<?php
include 'sam.php';
echo "<br>";
22
OUTPUT
23
PROGRAM 11
Post,Request,Get Method
</body>
</html>
PROCESS.PHP
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Retrieve input values from the form
$input1 = $_POST["input1"];
$input2 = $_POST["input2"];
$input3 = $_POST["input3"];
24
OUTPUT
25