Untitled Document
Untitled Document
Output:-
$a = 10;
$b = 20;
<?php
$i = 0;
while ($i <= 30)
{
if ($i % 2 == 0)
{
echo "$i<br>";
}
$i = $i + 1;
}
?>
Output:-
<?php
for($i=0;$i<=30;$i++)
{
if($i%2==0) <?php
{
$i=0;
do
{
echo "$i<br>";
$i=$i+2;
}
while($i<=30);
?>
echo $a["meeta"]["phy"];
Output:- echo "<br>";
echo $a["meeta"]["chem"];
echo "<br>";
echo $a["megha"]["phy"];
echo "<br>";
echo $a["megha"]["chem"];
?>
Output: ?>
Output:-
⚫ demonstrate use of math
function
echo decbin(2);
echo "<br>";
echo dechex(10);
echo "<br>";
echo bindec(1000);
echo "<br>";
echo sin(3);
echo "<br>";
echo cos(3);
echo "<br>";
echo tan(10);
echo "<br>";
echo base_convert(1,2,10);
echo "<br>";
echo fmod(5,2);
echo "<br>";
$a=array(20,30,40,50,);
echo max(20,30,5,4,3);
echo "<br>"; echo $a[0] ,"<br>";
echo $a[1] ,"<br>";
echo min(1,3,4,5); echo $a[2] ,"<br>";
echo "<br>"; echo $a[3] ,"<br>";
?> Output:-
Output:-
<?php
if($a>0)
<?php {
echo "number is positive"; echo "<br>";
} print_r(array_intersect($a,$b));
if($a<0) echo "<br>";
{ print_r(array_reverse($a));
echo "number is negative"; echo "<br>";
} print_r(array_unique($b));
echo "<br>";
?> print_r(array_chunk($b,2));
echo "<br>";
print_r(array_count_values($b));
Output: echo "<br>";
print_r(array_pop($b));
echo "<br>";
print_r(array_sum($b));
echo "<br>";
print_r(array_push($b,30));
echo "<br>";
print_r(array_search(30,$a));
echo "<br>";
print_r(count($b));
echo "<br>";
?>
$a=array(10,20,30,40);
$b=array(50,60,"seventy","eighty");
print_r(array_merge($a,$b));
echo "<br>";
print_r(array_combine($a,$b));
echo "<br>";
print_r(array_diff($a,$b));
⚫ wap to demonstrate default
constructor
⚫write any program using if <?php
condition with for loop
?>
Output:-
⚫ wap to demonstrate
parametarized constructor
<?php
⚫ demonstrate use of class employee
parametarized constructor
{
public $id;
<?php
public $name;
function __construct($id,$name)
class employee
{
{
$this->id=$id;
public $id;
$this->name=$name;
public $name;
}
function __construct($id,$name)
function show()
{
{
$this->id=$id;
echo "id is:".$this->id."<br>". "name
$this->name=$name;
is:".$this->name;
}
}
function show()
}
{
$e=new employee(123,"abc");
echo "id is:".$this->id."<br>". "name
$e->show();
is:".$this->name;
}
?>
}
$e=new employee(123,"abc");
$e->show();
Output:-
?>
class sub extends multiplication
{
function show4()
{
echo $this->num1 -
$this->num2;
}
}
⚫ wap to implement multilevel $a = new sub();
inheritance
$a->show1();
<?php echo "<br>";
$a->show2();
class addition echo "<br>";
{ $a->show3();
public $num1; echo "<br>";
public $num2; $a->show4();
function show2()
{
echo $this->num1 +
$this->num2;
}
}
Output:-
<input type="text" name="t1"
⚫ do validation of webpage
id="t1"><br/>
<label> enter mobile no.</label>
validate.php <input type="text" name="t2"
<?php id="t2"><br/>
if <label>enter address:</label>
($_SERVER['REQUEST_METHOD' <textarea name="t3" id=t3"
] == 'POST') cols="50" rows="5">
{ </textarea><br/>
if (empty($_POST['t1'])) <label>select gender:</label>
{ <input type="radio" name="g"
echo "name can't be value="female">female
blank<br/>"; <input type="radio" name="g"
} value="male">male<br/>
<label>I have read the form</label>
if (!is_numeric($_POST['t3'])) <input type="checkbox" name="m"
{ value=""><br/>
echo "enter correct <input type="submit" name="b"
address<br/>"; value="submit"/>
} </form>
</body>
$p = '/^[1-9]{1}[0-9]{9}$/'; </head>
if (!preg_match($p, </html>
$_POST['t2']))
{ Output:-
echo "enter valid mobile
no<br/>";
}
}
?>
demo4.php
<html>
<head>
<title> Registration Form</title>
<body>
<form method="post"
action="validate.php">
<label> enter name: </label>
Output:-
if ($msg == 0)
{
echo "Data recorded
successfully";
}
?>
⚫ wap to create modify and delete a cookie
<?php
if (!isset($_COOKIE['user']))
{
setcookie('user', 'janhavi', time() + (86400 * 30), "/");
echo "Cookie 'user' is set!<br>";
}
else {
echo "Cookie 'user' is already set. Its value is: " . $_COOKIE['user'] . "<br>";
}
if (isset($_COOKIE['user']))
{
if (isset($_COOKIE['user']))
{
session_start();
if (!isset($_SESSION['username']))
{
$_SESSION['username'] = 'Janhavi';
echo "Session started. Username is set to: " . $_SESSION['username'] .
"<br>";
}
else
{
session_unset();
session_destroy();
echo "Session destroyed.";
}
?>
⚫ wap to retrieve and present data from database
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "my_database";
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT id, name, email FROM users"; // Modify the query according
to your table structure
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// Output data for each row
echo "<table border='1'>";
echo "<tr><th>ID</th><th>Name</th><th>Email</th></tr>"; // Table
headers
while($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "</tr>";
}
echo "</table>";
} else {
echo "0 results found";}
$conn->close();
}
⚫ write a php program to insert data into employee table
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "company";
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$conn->close();
?>
⚫ write a php program to update table data from student database
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "school";
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$student_id = $_POST['student_id'];
$new_name = $_POST['name'];
$new_age = $_POST['age'];
$new_class = $_POST['class'];
$conn->close();
?>
</body>
</html>