Practical No.
1 :-
a) Install and configure PHP , web server, MYSQL
b) Write a program to print “Welcome To PHP”
=>
<?php
echo "Welcome To PHP";
?>
Output :-
c) Write a simple PHP program using expressions and Operators.
=>
<?php
echo "Operators <br>"; echo "<br>";
// Arithmetic Operators
$a = 10;
$b = 5;
$sum = $a + $b;
$difference = $a - $b;
$product = $a * $b;
$quotient = $a / $b;
$modulus = $a % $b;
// Comparison Operators
$isEqual = ($a == $b);
$isGreater = ($a > $b);
$isLess = ($a < $b);
// Logical Operators
$logicalAnd = ($a > 0 && $b > 0);
$logicalOr = ($a > 0 || $b < 0);
$logicalNot = !($a == $b);
// Bitwise Operators
$bitwiseAnd = $a & $b; // AND
$bitwiseOr = $a | $b; // OR
$bitwiseXor = $a ^ $b; // XOR
$bitwiseNotA = ~$a; // NOT
$bitwiseLeftShift = $a << 1; // Left shift
$bitwiseRightShift = $a >> 1; // Right shift
// Conditional (Ternary) Operator
$max = ($a > $b) ? $a : $b;
$min = ($a < $b) ? $a : $b;
// String Operators
$str1 = "Hello";
$str2 = "World";
$concatenation = $str1 . $str2;
// Output results
echo "Sum: $sum <br>";
echo "Difference: $difference <br>";
echo "Product: $product <br>";
echo "Quotient: $quotient <br>";
echo "Modulus: $modulus <br>";
echo "Is Equal: " . ($isEqual ? 'true' : 'false') . "<br>";
echo "Is Greater: " . ($isGreater ? 'true' : 'false') . "<br>";
echo "Is Less: " . ($isLess ? 'true' : 'false') . "<br>";
echo "Logical AND: " . ($logicalAnd ? 'true' : 'false') . "<br>";
echo "Logical OR: " . ($logicalOr ? 'true' : 'false') . "<br>";
echo "Logical NOT: " . ($logicalNot ? 'true' : 'false') . "<br>";
echo "Bitwise AND: $bitwiseAnd <br>";
echo "Bitwise OR: $bitwiseOr <br>";
echo "Bitwise XOR: $bitwiseXor <br>";
echo "Bitwise NOT (~$a): $bitwiseNotA <br>";
echo "Bitwise Left Shift ($a << 1): $bitwiseLeftShift <br>";
echo "Bitwise Right Shift ($a >> 1): $bitwiseRightShift <br>";
echo "Maximum value: $max <br>";
echo "Minimum value: $min <br>";
echo "Concatenated String: $concatenation <br>";
?>
Output :-
Practical No. 2
Write a PHP program to demonstrate the use of decision making control structures using
a. if statement
b. if-else statement
c. switch statement
if statement =>
<?php
$age = 20;
if ($age >= 18)
{
echo "You are eligible to vote.";
}
?>
Output :-
If-else statement =>
<?php
$number = 45;
if ($number % 2 == 0)
{
echo "$number is an even number.";
}
else
{
echo "$number is an odd number.";
}
?>
Output :-
Switch Statement =>
<html> <body>
<h3> Switch Statement </h3>
<?php
$ch=2;
$a=10;
$b=45;
switch($ch)
{
case 1:
echo( "Addition:".($a+$b));
break;
case 2:
echo( "Substraction:".($a-$b));
break;
}
?> </body> </html>
Output :-
Practical No. 3
Write a PHP program to demonstrate the use of looping structures using –
a. While statement
b. Do While statement
c. For statement
d. Foreach Statement
While Statement =>
<?php
$a=1;
$b=5;
echo "Table of 5:<br>";
while($a<=10)
{
echo ($b). "*" .($a). "=".($a*$b)."<br>";
$a++;
}
?>
Output :-
Do-while statement =>
<?php
$n=5;
$i=1;
echo "Table of 5:<br>";
do
{
echo ($n). "*" .($i). "=".($n*$i)."<br>";
$i++;
}while($i<=10);
?>
Output :-
For Statement =>
<?php
$i=10;
for($i=1;$i<=10;$i++)
{
echo $i."<br>";
}
?>
Output :-
Foreach loop :-
<?php
$arr=array('Nupur','Gauri','Rushika');
echo "Array Elements Are:<br>";
foreach($arr as $value)
{
echo($value)."<br>";
}
?>
Output:-
Practical No. 4
Write a PHP program for creating and manipulating –
a. Indexed Array
b. Associative Array
c. Multidimensional Array
Indexed Array =>
<?php
$arr=array('Mumbai','Pune','Nashik');
echo "The array Elements are:<br> ".$arr[0].",".$arr[1].",".$arr[2];
?>
Output :-
Associative Array =>
<?php
$capital=array("Name1"=>"Nupur","Name2"=>"Gauri", "Name3"=>"Rushikaa");
print_r($capital);
echo"<br>";
?>
Output:-
Multidimensional Array :-
<?php
$student=array(
array("Nupur","Pardeshi",15),
array("Rushika","Wagh",14),
array("Gauri","Rathod",12),
);
foreach($student as $student)
{
echo $student[0]." ".$student[1]." is ".$student[2]." years old.<br>";
}
?> Output:-