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

22203a0063 Prac 4,6

The document outlines laboratory exercises for a 6th semester Computer Engineering course, focusing on PHP programming. It includes tasks for creating and manipulating indexed, associative, and multidimensional arrays, as well as implementing various array functions and managing daily restaurant orders. Each exercise is accompanied by PHP code examples and expected outputs.

Uploaded by

pawararya2024
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)
8 views12 pages

22203a0063 Prac 4,6

The document outlines laboratory exercises for a 6th semester Computer Engineering course, focusing on PHP programming. It includes tasks for creating and manipulating indexed, associative, and multidimensional arrays, as well as implementing various array functions and managing daily restaurant orders. Each exercise is accompanied by PHP code examples and expected outputs.

Uploaded by

pawararya2024
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

DEPARTMENT OF COMPUTER ENGINEERING

Subject: WBP Subject Code:22619


Semester: 6th Semester Course: Computer Engineering
Laboratory No: L001C Name of Subject Teacher: Prof. Sneha Patange
Name of Student: Arya Pawar Roll Id: 22203A0063

Experime Title of Experiment Application


nt No:

4 Write a PHP program for creating and 1. Script to traverse indexed array
manipulating a)Indexed array ,associative array and multidimensional
b)associative array c)Multidimensional array using for and foreach loop.
array 2. Script to implement array inbuilt
function
3.Write php script to manage and
analyze daily order restaurent should
develop following requirements:
a. add new orders
b. delete and orders
6 Write a PHP program for creating and c. count total no of orders
manipulating a)Indexed array d. identify most ordered dish for the day
b)associative array c)Multidimensional e. display all the dishes ordered without
duplication
array
4.Write a script to implement concept
of variable function
5.Write a script to implement concept
of anonymous function
XI. Exercise

1. Develop a program for indexed array using for loop

<?php
$subjects=array("PHP","MAD","MANAGEMENT","PYTHON","EDE");
for ($x=0;$x<5;$x++)
{
print ($subjects[$x]."\n");
}
?>

.
Develop a program for indexed array using for each loop

<?php
$subjects=array("PHP","MAD","MANAGEMENT","PYTHON","EDE");
foreach ($subjects as $i)
{
print ($i."\n");
}
?

Output:

Develop a program for associative array using for each loop

<?php
$data=array("PHP"=>20,"MAD"=>30,"MANAGEMENT"=>20,"PYTHON"=>45,"EDE"=>20);
foreach ($data as $sub=>$m)
{
print ("<br>subject:".$sub."<br>marks:".$m);
print "<br>";
}
?>
Output:

Develop a program for associative array using for loop


<?php
$data=array("PHP"=>20,"MAD"=>30,"MANAGEMENT"=>20,"PYTHON"=>45,"EDE"=>20);
$subjects=array_keys($data);

for ($i=0;$i<count($data);$i++)
{
$marks=$data[$subjects[$i]];
print ("<br>subject:".$subjects[$i]);
print ("<br>marks:".$marks);
print"<br>";

}
?>
Output:
Develop a program for multidimensional array using for loop

<?php
$students = array(
array("RollNo" => 47, "Name" => "Shrushti", "Marks" => 85),
array("RollNo" => 49, "Name" => "Sanjana", "Marks" => 90),
array("RollNo" => 36, "Name" => "Shalaka", "Marks" => 88)
);

for ($i = 0; $i < count($students); $i++) {


$keys = array_keys($students[$i]);

for ($j = 0; $j < count($keys); $j++) {


print("\n" . $keys[$j] . ": " . $students[$i][$keys[$j]]);
}
print("\n");
}
?>
Output:
Develop a program for multidimensional array using foreach loop

<?php
$students = array(
47 => array("name" => "Shrushti", "age" => 20, "grade" => "A"),
49 => array("name" => "Sanjana", "age" => 21, "grade" => "B"),
36 => array("name" => "Shalaka", "age" => 22, "grade" => "A")
);

foreach ($students as $rollno => $details) {


echo "\nRoll No: $rollno";
foreach ($details as $key => $value) {
echo "\n$key: $value";
}
echo "\n";
}
?>
Output:

2. Write a program to implement all array functions


<?php
$a1 = array("PHP", "Python", "Java", "C", "HTML");
$a2 = array("PHP", "Ruby", "Java", "Go", "HTML");

echo "array_diff: <br>";


print_r(array_diff($a1, $a2));

echo "<br><br>array_intersect: <br>";


print_r(array_intersect($a1, $a2));

echo "<br><br>array_chunk: <br>";


print_r(array_chunk($a1, 2, true));

$keys = array("PHP", "Python", "Java");


$values = array("10", "20", "30");
echo "<br><br>array_combine: <br>";
print_r(array_combine($keys, $values));

$a3 = array("PHP", "Python", "Java", "Python", "C");


echo "<br><br>array_unique: <br>";
print_r(array_unique($a3));

echo "<br><br>array_count_values: <br>";


print_r(array_count_values($a3));

$a4 = array("HTML", "CSS");


echo "<br><br>array_merge: <br>";
print_r(array_merge($a1, $a4));
echo "<br><br>array_pop: <br>";
array_pop($a1);
print_r($a1);

$a5 = array(2, 3, 4);


echo "<br><br>array_product: <br>" . array_product($a5);

array_push($a1, "Swift", "Kotlin");


echo "<br><br>array_push: <br>";
print_r($a1);

echo "<br><br>array_reverse: <br>";


print_r(array_reverse($a1));

echo "<br><br>array_search: <br>";


echo array_search("Java", $a1) . "<br>";

$a6 = array(5, 10, 15);


echo "<br>array_sum: <br>" . array_sum($a6) . "<br>";

echo "<br>count: <br>" . count($a1) . "<br>";

?>

Output:
3. Write php script to manage and analyze daily order restaurent should develop following
requirements:
1. add new orders
2. delete and orders
3. count total no of orders
4. identify most ordered dish for the day
5. display all the dishes ordered without duplication*/

<?php
$orders=[];
//add dish
function addNewOrder(&$orders, $dish){
$orders[]=$dish;
echo ("\nOrder Placed: $dish");
}

//delete dish
function deleteOrder(&$orders, $index){
if (empty($orders)){
echo "\nNo such item found";
}
else{
echo ("\nOrder Placed: $orders[$index]");
unset($orders[$index]);
}
}
//count dish
function countAllDishes(&$orders){
return count($orders);
}
//unique dish
function dishUnique(&$orders){
return (array_unique($orders));
}
//most ordered dish
function mostOrdered(&$orders){
array_count_values($orders);
arsort($orders);
$most=$orders[0];
return $most;
}
addNewOrder($orders, "chakli");
addNewOrder($orders, "karanji");
addNewOrder($orders, "shev");
addNewOrder($orders, "besan ladoo");
addNewOrder($orders, "tes");
addNewOrder($orders, "tea");
deleteOrder($orders, 1);
echo ("\n\nOrder Summary\n");
echo ("\nDishes ordered: ");
print_r ($orders);
echo ("\nNo of dishes placed: ".countAllDishes($orders)."\n");
echo ("\nMost ordered dish: ".mostOrdered($orders)."\n");
print ("\nUnique dishes: ");
print_r(dishUnique($orders));

?>
Output:
4. Write a script implement concept of variable function
<?php
function greet() {
echo "Hello, Welcome to PHP!";
}
$func = "greet";
$func();
?>
Output:

5. Write a script to implement concept of anonymous function


<?php
$greet = function () {
echo "Hello, Welcome Students";
};
$greet();
?>
Output:

You might also like