Professional Documents
Culture Documents
All Practicals
All Practicals
$number = (int)$number;
if ($number % 2 == 0) {
echo "The number $number is even.\n";
} else {
echo "The number $number is odd.\n";
}
?>
Output:
Enter a number: 4
The number 4 is even.
Output:
<?php
Output:
Pyramid of Stars:
*
***
*****
*******
*********
Marks obtained Dated signature of
Teacher
Process Product Total(50)
Related(35) Related(15)
Exercise
Output:
<?php
$classroom = array(
"Raj" => array("Math" => 85, "Science" => 92, "English" => 78),
"Raghav" => array("Math" => 90, "Science" => 88, "English" => 95),
"Atharva" => array("Math" => 82, "Science" => 90, "English" => 85)
);
Student: Raj
Subject: Math, Grade: 85
Subject: Science, Grade: 92
Subject: English, Grade: 78
Student: Raghav
Subject: Math, Grade: 90
Subject: Science, Grade: 88
Subject: English, Grade: 95
Student: Atharva
Subject: Math, Grade: 82
Subject: Science, Grade: 90
Subject: English, Grade: 85
$number = -10;
echo "Absolute Value of $number: " . abs($number) . "\n";
$floatNumber = 10.67;
echo "Round of $floatNumber: " . round($floatNumber) . "\n";
$floatNumber = 10.01;
echo "Ceiling of $floatNumber: " . ceil($floatNumber) . "\n";
$floatNumber = 10.99;
echo "Floor of $floatNumber: " . floor($floatNumber) . "\n";
?>
Output:
Number 1: 25
Number 2: 10
Power: 95367431640625
Square Root of 25: 5
Absolute Value of -10: 10
Round of 10.67: 11
Ceiling of 10.01: 11
Floor of 10.99: 10
function sayHello($name) {
echo "Hello, $name!\n";
}
sayHello("Raj");
sayHello("Raghav");
sayHello("Atharva");
?>
Output:
Hello, Raj!
Hello, Raghav!
Hello, Atharva!
Output:
<?php
class Car {
public $brand;
public $model;
Output:
Output:
Serialized Data: a:3:{s:4:"name";s:3:"Raj";s:3:"age";i:30;s:4:"city";s:11:"Nevi Mumbai";}
Deserialized Data:
Array
(
[name] => Raj
[age] => 30
[city] => Nevi Mumbai
)
function area()
{
return $this->dim1 * $this->dim2;
}
function display()
{
}
}
$class_properties = get_class_vars("Rectangle");
$object_properties = get_object_vars($S);
$class_methods = get_class_methods("Rectangle");
$object_class = get_class($S);
print_r($class_properties);
print_r($object_properties);
print_r($class_methods);
print_r($object_class);
?>
Output:
Array
(
[dim1] => 2
[dim2] => 10
)
Array
(
[dim1] => 2
[dim2] => 10
)
Array
(
[0] => Rectangle
[1] => area
[2] => display
)
Rectangle
index.html
<html>
<body>
<form method="post" action="validate.php">
<label for="name">Name:</label>
<input type="text" id="name" name="name"><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
validate.php
<?php
$name = isset($_POST["name"]) ? $_POST["name"] : "";
$email = isset($_POST["email"]) ? $_POST["email"] : "";
index.html
<html>
<body>
<form method="post" action="validate.php">
<label for="cars">Select a car:</label>
<select id="cars" name="cars[]" multiple>
<option value="Tata">Tata</option>
<option value="Mahindra">Mahindra</option>
<option value="KiA">KiA</option>
<option value="Hero Honda">Hero Honda</option>
</select><br><br>
validate.php
<?php
$cars = isset($_POST["cars"]) ? $_POST["cars"] : [];
$userid = isset($_POST["userid"]) ? $_POST["userid"] : "";
$gender = isset($_POST["gender"]) ? $_POST["gender"] : "";
Output:
validate.php
<?php
$email = isset($_POST["email"]) ? $_POST["email"] : "";
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo "<p>$email is Valid email.<p>";
} else {
echo "<p>$email is not valid email.<p>";
}
?>
Output:
session_destroy();
Output:
2) subject (required): The subject line of the email. It should be a brief summary of the email's content.
3) message (required): The actual message content of the email. This can be plain text or HTML formatted
content.
4) headers (optional): Additional email headers, such as From, Cc, Bcc, Reply-To, etc. These headers are
typically used to set the sender's email address, reply-to address, and other email parameters. It should be
formatted as a string.
5) parameters (optional): Additional parameters that can be used to specify options for sending the email.
This is rarely used and can be left empty in most cases.
<?php
$conn = new mysqli("localhost", "root", "", "atharva");
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$conn->close();
?>
Output:
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
Output: