0% found this document useful (0 votes)
13 views12 pages

Writing Shit

The document outlines various PHP experiments, including arithmetic operations, conditional statements, and loops. It provides code examples for checking even or odd numbers, determining if a number is positive, negative, or zero, and generating patterns using loops. Additionally, it discusses operators in PHP and the execution steps for PHP programs using XAMPP.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views12 pages

Writing Shit

The document outlines various PHP experiments, including arithmetic operations, conditional statements, and loops. It provides code examples for checking even or odd numbers, determining if a number is positive, negative, or zero, and generating patterns using loops. Additionally, it discusses operators in PHP and the execution steps for PHP programs using XAMPP.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

EXP 1

2.
<?php
echo"<h1> Practical 1</h1>";
echo"Welcome to PHP";
echo"<br>";
echo"Performed By Muskan"
?>

3.

<html>
<title>Arithmetic Operations</title>
<body>
<center>
<h1>
<b>
<?php
echo("EXPERIMENT 1");
echo("<br>Arithmetic Operations");
echo("<br>Performed by: MUSKAN KATEJA");

// Predefined values
$num1 = 2; // First number
$num2 = 10; // Second number

// Perform arithmetic operations


$addition = $num1 + $num2;
$subtraction = $num1 - $num2;
$multiplication = $num1 * $num2;

// Division operation without using ternary operator


if ($num2 != 0) {
$division = $num1 / $num2;
} else {
$division = 'Undefined (division by zero)';
}

// Display results
echo "<h2>Results:</h2>";
echo "Addition: $num1 + $num2 = $addition<br>";
echo "Subtraction: $num1 - $num2 = $subtraction<br>";
echo "Multiplication: $num1 * $num2 = $multiplication<br>";
echo "Division: $num1 / $num2 = $division<br>";
?>
</b>
</h1>
</center>
</body>
</html>

Exercise

1. Write various comparison operators in PHP with example.

2. Write various Logical operators in PHP with example.


PRQ:
1.
Steps to Execute a PHP Program Using XAMPP:
1. Install XAMPP and ensure it's set up correctly.
2. Start the Apache server from the XAMPP Control Panel.
3. Write your PHP code and save it with a `.php` extension.
4. Save the file in the `htdocs` folder (usually `C:\xampp\htdocs`).
5. Open a browser and navigate to `http://localhost/yourfilename.php`.

2.

2. Different Operators Supported by PHP (Examples for Two Types):

1. Arithmetic Operators

Used for mathematical operations like addition, subtraction, etc.​


Example:

<?php
$a = 10;
$b = 5;
echo "Addition: " . ($a + $b); // Output: 15
echo "Multiplication: " . ($a * $b); // Output: 50
?>

2. Comparison Operators
Used to compare two values.​
Example:

<?php
$x = 20;
$y = 15;
echo ($x > $y) ? "x is greater than y" : "x is not greater than y";
// Output: x is greater than y
?>

Exp 2

20
<!DOCTYPE html>
<html>
<head>
<title>Even or Odd Checker</title>
<style>
body {
text-align: center;
}
</style>
</head>
<body>
<h1>Even or Odd Checker</h1>
<?php
$number = 5;
if ($number % 2 == 0) {
echo "<p>$number is even.</p>";
} else {
echo "<p>$number is odd.</p>";
}
?>
<p>Developed by Zeal Gala</p>
</body>
</html>

Page 22 Q1

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Check Number</title>
</head>
<body>

<h1>Check if a Number is Positive, Negative, or Zero</h1>

<?php
$number = -5; // Change this value to test different numbers

// Check if the number is positive, negative, or zero


if ($number > 0) {
echo "<p>The number <strong>$number</strong> is positive.</p>";
} elseif ($number < 0) {
echo "<p>The number <strong>$number</strong> is negative.</p>";
} else {
echo "<p>The number is zero.</p>";
}
?>

<div>
<p>Developed by Muskan Kateja</p>
</div>

</body>
</html>
22 Q2

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Check Number</title>
</head>
<body>

<h1>Check if a Number is Positive, Negative, or Zero</h1>

<?php
$number = -5; // Change this value to test different numbers
// Check if the number is positive, negative, or zero
if ($number > 0) {
echo "<p>The number <strong>$number</strong> is positive.</p>";
} elseif ($number < 0) {
echo "<p>The number <strong>$number</strong> is negative.</p>";
} else {
echo "<p>The number is zero.</p>";
}
?>

<div>
<p>Developed by Zeal Gala</p>
</div>

</body>
</html>

22 q3

<!DOCTYPE html>
<html>
<head>
<title>Day Finder</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<h1>Day Finder</h1>
<?php
$mon = date('N');
switch ($mon){

case '1':
echo "Today is Monday";
break;

case '2':
echo "Today is Tuesday";
break;

case '3':
echo "Today is Wednesday";
break;
case '4':
echo "Today is Thursday";
break;

case '5':
echo "Today is Friday";
break;

case '6':
echo "Today is Saturday";
break;

case '7':
echo "Today is Sunday";
break;

default:
echo "Not a valid Day";
break;
}
?>

<br><br><b>Developed by Muskan Kateja</b>


</div>
</body>
</html>

PRQ

1. List operators used in if conditional statements.

●​ Comparison Operators:
○​ == (equal to)
○​ != (not equal to)
○​ > (greater than)
○​ < (less than)
○​ >= (greater than or equal to)
○​ <= (less than or equal to)
●​ Logical Operators:
○​ && (logical AND)
○​ || (logical OR)
○​ ! (logical NOT)
2. In if-else construct which part will be executed if condition is true.

The if part will be executed if the condition is true.

Example:

<?php
$age = 18;
if ($age >= 18) {
echo "You are an adult."; // This will execute as the condition is true.
} else {
echo "You are a minor.";
}
?>

3. State the condition when the else part will be executed with example.

The else part will be executed when the condition in the if statement is false.

Example:

<?php
$age = 15;
if ($age >= 18) {
echo "You are an adult.";
} else {
echo "You are a minor."; // This will execute as the condition is false.
}
?>

Exp 3

Page - 27

<!DOCTYPE html>
<html>
<head>
<title>First 30 Even Numbers</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<h1>First 30 Even Numbers</h1>

<h2>Using for loop:</h2>


<?php
for ($i = 1; $i <= 30; $i++) {
echo ($i * 2) . " ";
}
?>

<h2>Using while loop:</h2>


<?php
$i = 1;
while ($i <= 30) {
echo ($i * 2) . " ";
$i++;
}
?>

<h2>Using do-while loop:</h2>


<?php
$i = 1;
do {
echo ($i * 2) . " ";
$i++;
} while ($i <= 30);
?>

<b>Developed by Mohit Gurnani</b>


</div>
</body>
</html>

Page - 29

1.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Factorial Experiment</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>

<h1>Experiment 4: Factorial Calculation</h1>


<p class="question">Question: Write any program using if condition with for loop</p>
<p>{ Factorial of numbers from 1 to 5 }</p>

<?php
function calculateFactorial($number) {
$factorial = 1;
if ($number < 0) {
return "Factorial is not defined for negative numbers.";
} else {
for ($i = 1; $i <= $number; $i++) {
$factorial *= $i;
}
return $factorial;
}
}
for ($i = 1; $i <= 5; $i++) {
echo "<p class='factorial'>The factorial of $i is " . calculateFactorial($i) . "</p>";
}
?>
<p class="developer">Developed by Mohit Gurnani</p>
</body>
</html>

2.
2.1 (star wala)

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Star Pattern Experiment (Incrementing)</title>
<link rel="stylesheet" href="main.css">
</head>
<body>

<h1>Experiment 4: Star Pyramid Pattern (Incrementing)</h1>


<p class="question">Question: Write a program to display pyramid of stars/patterns using
increment</p>

<p>{ Star Pattern Incrementing (5 lines) }</p>

<?php
// Program to print an incrementing pyramid of stars (left aligned)
echo "<div class='pattern'>";
for ($i = 1; $i <= 5; $i++) {
for ($j = 1; $j <= $i; $j++) {
echo "* "; // Print stars for incrementing pattern
}
echo "<br>";
}
echo "</div>";
?>

<p class="developer">Developed by Muskan Kateja</p>

</body>
</html>

2.2

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Number Pattern Experiment (Decrementing)</title>
<link rel="stylesheet" href="main.css">
</head>
<body>

<h1>Experiment 4: Number Pyramid Pattern (Decrementing)</h1>


<p class="question">Question: Write a program to display pyramid of numbers/patterns using
decrement</p>

<p>{ Number Pattern Decrementing (5 to 1) }</p>

<?php
// Program to print a decrementing pyramid of numbers (left aligned)
echo "<div class='pattern'>";
for ($i = 5; $i >= 1; $i--) {
for ($j = 1; $j <= $i; $j++) {
echo "$i "; // Print numbers for decrementing pattern
}
echo "<br>";
}
echo "</div>";
?>
<p class="developer">Developed by Muskan Kateja</p>

</body>
</html>

PRQ

1. When for loop will be terminated?

●​ A for loop terminates when the loop condition becomes false. The loop runs as long
as the specified condition evaluates to true.
●​ The termination occurs after completing one iteration of the loop if the condition is no
longer met.

Example:

php
CopyEdit
<?php
for ($i = 0; $i < 5; $i++) {
echo $i; // This will print 0 to 4
}
?>

In the above example, the loop will terminate when $i becomes 5 because the condition $i <
5 will then be false.

2. Difference between for and for-each loop

You might also like