0% found this document useful (0 votes)
936 views30 pages

PHP & MySQL Web Design Diploma Syllabus

The document provides information about a course on Web Designing Using PHP and MySQL. It includes the course code, teaching scheme details, course outcomes and a practical list with tasks to develop scripts using basic PHP concepts like variables, operators, functions etc. It aims to help students learn how to create dynamic websites and web applications using PHP and MySQL database. Sample programs are provided as solutions to demonstrate concepts like variables scope, constants, operators. Questions are also included to check understanding of concepts like WAMP/LAMP/XAMPP and PHP being a loosely typed language.

Uploaded by

Raj Mahadevwala
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)
936 views30 pages

PHP & MySQL Web Design Diploma Syllabus

The document provides information about a course on Web Designing Using PHP and MySQL. It includes the course code, teaching scheme details, course outcomes and a practical list with tasks to develop scripts using basic PHP concepts like variables, operators, functions etc. It aims to help students learn how to create dynamic websites and web applications using PHP and MySQL database. Sample programs are provided as solutions to demonstrate concepts like variables scope, constants, operators. Questions are also included to check understanding of concepts like WAMP/LAMP/XAMPP and PHP being a loosely typed language.

Uploaded by

Raj Mahadevwala
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/ 30

I.T.

Dept Year 2021 3361603 (WEB DESINGING USING PHP AND MYSQL)

Course : Web Designing Using PHP and

MYSQL(3361603) Branch: Diploma in

Information Technology

SEM:6

Teaching & Examination Scheme:

Examination Scheme
Teaching Total
Scheme Credits Tot
Theory Practical
(in (L+T+ Marks Marks al
Hours) P) Ma
rks
L T P Cre E P E P
dit S A S A 20
E E 0
3 0 4 7 7 3 4 6
0 0 0 0
Legends: L - Lecture; T - Tutorial/Teacher Guided Student Activity; P - Practical;
ESE - End Semester Examination; PA - Progressive Assessment

Course Outcomes:

CO-1 Develop a simple script using basic PHP concepts.


CO-2 Apply In-Built and User defined functions in PHP
scripts.
Develop interactive Web pages using various form
CO-3
controls and methods.
Apply the concept of state management for
CO-4
building web applications.
Create dynamic Website/ Web based Application
CO-5
using PHP and MySQL database.

SEM-6 1
I.T. Dept Year 2021 3361603 (WEB DESINGING USING PHP AND MYSQL)

CO-1 Develop simple script using basic PHP concepts.

PRACTICAL
LIST – 1

1.1 Write a PHP script to display welcome message && write a PHP script to
display a given paragraph.
1.2 Write a PHP script to demonstrate use of global and local and static and
constant variables.
1.3 Write a PHP script to demonstrate arithmetic operators, comparison
operator, and logical operator.
1.4 Write PHP Script to print Fibonacci series of ten numbers.
1.5 Write a PHP script to find a factorial of n using Recursive Function.
1.6 Write a PHP script to Fibonacci series in html tabular format.
1.7 Write PHP Script to generate results and display grades.
1.8 Write a PHP Script to show different looping structures.
1.9 Write PHP Script to find the maximum number out of three given numbers
with and without Command line.
1.10 Write a PHP script to call by reference and call by value.
1.11 Write PHP script to display table of number 11.
1.12 Write PHP Script for addition and multiplication of two 2x2 matrices.
1.13 Write a PHP Script for numeric, Associative and multidimensional array.
1.14 Write a PHP script to Find Perimeter and area of rectangle using
parameterized function.
1.15 Write a PHP Script for performing functions that takes arguments,
returns arguments, default argument and variable length argument.
1.16 Write a PHP script to find var args that uses to find max and minimum of
Passed parameters

SEM-6 2
I.T. Dept Year 2021 3361603 (WEB DESINGING USING PHP AND MYSQL)

Aim:
1.1 Write a PHP script to display welcome messages and write a php script to
display a given paragraph.
1.2 Write a PHP script to demonstrate use of global and local and static and
constant variables.
Software Required: Text Editor, Wamp/Xampp
Prerequisite: Basic knowledge of editor

Theory/Logic:
 Structure:-
<? php
………………………………………………………..
// Code or statement to be execute on server side
………………………………………………………..
?>
l Whenever requesting a web page with .php extension the server locates
the requested file and executes the script that is specified between <? php
and ?> tag and returns output in form of just HTML back to the user.
 Rules of php syntax:-
 You must follow following rules for PHP syntax:-
 The script of PHP must contain between <? php ?>
 Every statement inside <? php ?> must end with a semicolon.
 String must contain between either single quotation mark or double
quotation mark.
 You can make a line as a comment using either // or /* */.No other
symbols are permitted for making a line as a comment.
 Every variable in a script must start with $ sign.
 Name of the variable cannot start with a digit and it cannot contain white
spaces.
 PHP is case sensitive.
 Constants in php:-
Syntax:-
define (name, value, case-insensitive)
l name: Specifies the name of the constant
l value: Specifies the value of the constant
l Case-insensitive: Specifies whether the constant name should
be case-insensitive. Default is false.
 Static Variable:-
Syntax:-
Static
$VariableName=value;

SEM-6 3
I.T. Dept Year 2021 3361603 (WEB DESINGING USING PHP AND MYSQL)

 Xampp installation:-
step 1:-
Download from respected version according to machine’s OS
from https://www.apachefriends.org/download.html
step 2:-
run the setup wizard

step 3:-
work through the graphical setup wizard
step 4:-

verify the installation by running the following command.

SEM-6 4
I.T. Dept Year 2021 3361603 (WEB DESINGING USING PHP AND MYSQL)

Program/Solution 1.1:
<?php
echo('<h1>Welcome to Night Owls</h1>');
echo('We are Night Owls. We are a creative group <br>
of people who design <br>
influential websites and <br>
digital experiences.');
?>

Output 1.1:

SEM-6 5
I.T. Dept Year 2021 3361603 (WEB DESINGING USING PHP AND MYSQL)

Program/Solution 1.2:
<?php
//static scope
function staticTest() {
static $c = 0; //static variable
echo "static variable c $c <br>";
$c++;
}
echo'<h2>Static counter</h2>';
staticTest();
staticTest();
staticTest();

//Constants
echo "<h2> Constants </h2>";
define("Me", "Web Developer");
define("You", "Flutter Developer");
echo('Proffesion of Mine :'.Me );
echo('<br>Proffesion of Yours:'.You );

$a = 10; // global scope


function globalTest() {
global $b;
$b = $GLOBALS['a']+5;
// using a inside this function will generate an error
echo "<br>Variable a inside function globalTest generates an error";
echo $a;
}
echo "<h2>Global Scope</h2>";
globalTest();
echo "<p>Variable a outside function is: $a</p>";
echo"<p>Variable b defined in the function with global keyword using outside
function: $b<br>";
?>

SEM-6 6
I.T. Dept Year 2021 3361603 (WEB DESINGING USING PHP AND MYSQL)

Output 1.2:

Questions:
1 Write down the full form of WAMP, LAMP and XAMPP.
 WAMP: Windows, Apache, MySQL and PHP
 LAMP: Linux, Apache, MySQL and PHP
 XAMPP: Cross-platform, Apache, MySQL,PHP and Perl

2 Justify: PHP is a Loosely Typed Language.


 in the program above , notice that we did not have to tell PHP which data
type the variable is.
 PHP automatically associates a data type to the variable, depending on its
value. Since the datatype is not set in strict sense, you can do things like
adding string to an integer without causing error.

SEM-6 7
I.T. Dept Year 2021 3361603 (WEB DESINGING USING PHP AND MYSQL)

1.3 Write a PHP script to demonstrate arithmetic operators, comparison


operator, and logical operator
Software Required: Text Editor, Wamp/Xampp
Prerequisite: Basic knowledge of editor
Theory/Logic:
● Operators are used to perform operations on variables and values.

● PHP divides the operators in the following groups:


❑ Arithmetic ❑ Increment/Decrement operators
operators ❑ Logical operators
❑ Assignment ❑ String operators
operators ❑ Array operator
❑ Comparison
operators

Arithmetic operator:-

Comparison Operators:-

SEM-6 8
I.T. Dept Year 2021 3361603 (WEB DESINGING USING PHP AND MYSQL)

Logical Operators:-

Program/

Solution:

<?php
$x = 10;
$y = 15;
$z='15';
echo("<h3>x=10,y=15</h3><h4>Arithmetic Operators:</h4>x+y:".($x+$y).'<br>x-
y:'.($x-$y).'<br>x*y:'.($x*$y).'<br>y/x:'.($x/$y).'<br>x%y:'.($x%$y).'<br>y**x:'.$y**$x);
echo('<hr><h3>x=10, y=15, z=15(string)</h3><h4>Comparison
Operators</h4>z==y: ');
var_dump($z==$y);
echo('<br>x===z: ');
var_dump($x===$z);
echo('<br> $x!=$y / $x<>$y: '.($x!=$y).'<br>$x!==10(string): '.($x!
=='10').'<br>$x<$y: '.($x<$y).'<br>$x>$y: '.($x>$y).'<br>$x<=5: '.($x<=10).'<br>$x
<=> $y: '.($x <=> $y));
$x=true;
$y=false;
echo('<hr><h3>x=true, y=false<h3><h4>logical operator</h4>x and y: ');
var_dump($x and $y);
echo('<br>x or y: ');
var_dump($x or $y);
echo('<br>x xor y: ');
var_dump($x xor $y);
echo('<br>!x: ');
var_dump(! $x);
echo('<br>x && y: ');
var_dump($x && $y);
echo('<br>x || y: ');

SEM-6 9
I.T. Dept Year 2021 3361603 (WEB DESINGING USING PHP AND MYSQL)

var_dump($x || $y);
?>

Output:

Questions:
1 List out logical operators in PHP
 and
 or
 xor
 &&
 ||
!
2 List out Array operators in PHP.
+
 ==
 ===
 !=
 <>
 !==

SEM-6 10
I.T. Dept Year 2021 3361603 (WEB DESINGING USING PHP AND MYSQL)

1.4 Write PHP Script to print Fibonacci series.


1.5 Write a PHP script to find a factorial of n using Recursive Function.
1.6 Write a PHP script to Fibonacci series in html tabular format.
1.7 Write PHP Script to generate results and display grades.
1.8 Write a PHP Script to show different looping structures.

Software Required: Notepad, WordPad, Notepad++, Dreamweaver,


Wamp/Xampp
Prerequisite: Basic knowledge of editor
Theory/Logic:
In PHP we have the following conditional statements:
l PHP Conditional structure:-
l if statement - executes some code if one condition is true
l if...else statement - executes some code if a condition is true and another
code if that condition is false
l if...else if else statement - executes different codes for more than two
conditions
l Switch statement - selects one of many blocks of code to be executed.
l syntax:
Switch (n)
{ case
label1:
code to be executed if
n=label1; break;
case label2:
code to be executed if
n=label2; break;
default:
code to be executed if n is different from all labels;
}
l PHP looping structure:-
● It allows you to execute a certain portion of the script repeatedly based on
some condition.
● for - loops through a block of code a specified

number of times Syntax:-

◻ for (init counter; test counter; increment counter) {


code to be executed;
}
● foreach - loops through a block of code for each element in an array.

SEM-6 11
I.T. Dept Year 2021 3361603 (WEB DESINGING USING PHP AND MYSQL)

Syntax:-

◻ foreach ($array as $value)


{
code to be executed;
}

● while - loops through a block of code as long as the specified

condition is true Syntax:

◻ while (condition is true)


{
code to be executed;
}
● do...while - loops through a block of code once, and then repeats the
loop as long as the specified condition is true.

Syntax:

◻ do {
code to be executed;
} while (condition is true);

Program/Solution 1.4:
<?php
$n1 = 0;
$n2 = 1;
echo "<h3>Fibonacci series for first 10 numbers: </h3>";
echo "\n";
echo $n1.'<br>'.$n2.'<br>';
for ($num=0;$num<=8 ;$num++ )
{
$n3 = $n2 + $n1;
echo $n3.'<br>';
$n1 = $n2;
$n2 = $n3;
}
?>

SEM-6 12
I.T. Dept Year 2021 3361603 (WEB DESINGING USING PHP AND MYSQL)

Output 1.4:

Program/Solution 1.5:

<?php
function fact ($n){
if($n <= 1){
return 1;
}
else{
return $n * fact($n - 1);
}
}
echo "Factorial of 5 is " .fact(5);
?>

SEM-6 13
I.T. Dept Year 2021 3361603 (WEB DESINGING USING PHP AND MYSQL)

Output 1.5:

Program/Solution 1.6:

<h2 style="text-align:center;">Fibonacci Series</h2>


<?php
$n1=0;
$n2=1;
echo ('<table align="center" style="width:10%; background:yellow;",
border="2"><tr><th>index</th><th>value</th></tr><tr><td>1</td><td>0</td></
tr></tr><tr><td>2</td><td>1</td></tr>');
for ($num=3;$num<=10 ;$num++ )
{
$n3 = $n2 + $n1;
echo ("<tr><td>$num</td><td>$n3</td></tr>");
$n1 = $n2;
$n2 = $n3;
}
?>

SEM-6 14
I.T. Dept Year 2021 3361603 (WEB DESINGING USING PHP AND MYSQL)

Output 1.6:

Program/Solution 1.7:

<?php
echo "<table border='1' cellpadding='10'>";
echo "<tr><th><h2>Subject</h2></th><th><h2>Marks</h2></th><th><h2>Grade</h2></
th></tr>";
echo "<tr><th><h3>PHP</h3></th><td>95</td><td>".grade(95)."</td></tr>";
echo "<tr><th><h3>WNS</h3></th><td>80</td><td>".grade(80)."</td></tr>";
echo "<tr><th><h3>AJAVA</h3></th><td>85</td><td>".grade(85)."</td></tr>";
echo "<tr><th><h3>Android</h3></th><td>90</td><td>".grade(90)."</td></tr>";
function grade($mark){
switch ($mark) {
case ($mark<35):
return "Fail";
break;
case ($mark>=35 && $mark<=39):
return "DD";
break;
case ($mark>=40 && $mark<=44):
return "CD";
break;
case ($mark>=45 && $mark<=54):
return "CC";
break;
case ($mark>=55 && $mark<=64):
return "BC";
break;
case ($mark>=65 && $mark<=74):

SEM-6 15
I.T. Dept Year 2021 3361603 (WEB DESINGING USING PHP AND MYSQL)

return "BB";
break;
case ($mark>=75 && $mark<=84):
return "AB";
break;
case ($mark>=85 && $mark<=100):
return "AA";
break;
default:
return "Invalid!";
break;
}
}
?>
Output 1.7:

Program/Solution 1.8:

<?php
echo('<h3>While loop</h3>');//while loop
$x=0;
while($x <= 5) {
echo "N: $x <br>";
$x++;
}

$x=0;
echo('<hr><h3>Do while loop</h3>'); //do while loop
do {

SEM-6 16
I.T. Dept Year 2021 3361603 (WEB DESINGING USING PHP AND MYSQL)

echo "N: $x <br>";


$x++;
} while ($x <= 5);

echo('<hr><h3>For loop</h3>'); //For loop


for ($x = 0; $x <= 50; $x+=10) {
echo "N: $x <br>";
}

echo('<hr><h3>For each loop</h3>'); //For each loop


$Language = array("Dart","Android","PhP","C#");
foreach ($Language as $value) {
echo "from Language array $value <br>";
}

?>
Output 1.8:

Questions:

SEM-6 17
I.T. Dept Year 2021 3361603 (WEB DESINGING USING PHP AND MYSQL)

1 Differentiate for V/S foreach loop.

FOR FOREACH

Implemented over variables Implemented over Numerical and


associative arrays

Working till the end of the given Working till the end of the array
condition count

Syntax: Syntax:
for(expr1; expr2; expr3) foreach ($array as $value)
{//If expr2 is true, do this} {//Do Something}

2 In which situation foreach loop is used in PHP?


We can use the foreach to loop through an array it helps to iterate through
the array without knowing its size,no of elements.

SEM-6 18
I.T. Dept Year 2021 3361603 (WEB DESINGING USING PHP AND MYSQL)

1.9 Write PHP Script to find the maximum number out of three given numbers
with and without Command line.
1.10 Write a PHP script to call by reference and call by value.
1.11 Write PHP script to display table of number 11.

Software Required: Notepad, WordPad, Notepad++, Dreamweaver,


Wamp/Xampp
Prerequisite: Basic knowledge of editor

Theory/Logic:
Steps for run PHP scripts in command line:
1 Start a command prompt (Start button > Run > cmd.exe)
2 In the window that appears, type the full path to the PHP executable
(php.exe) followed by the full path to the script you wish to run as a
windows service. ...
3 Hit the Enter key to execute the command line.

Call by Value:-
▪ When you define a function that accepts arguments you must have to pass
those arguments while calling the function.
▪ If you pass the wrong number of arguments at the time of calling the
function then it will generate a warning message.
▪ In PHP you can define a function having a default argument.
▪ If you don’t pass value for that argument then it will consider default value
for that argument otherwise it will overwrite value for argument.
▪ You need to assign the value to the argument while defining the function.

Call by Reference:
▪ In this case, the address of the variable is passed into the function.
Change to the value within the function will be reflected in the variable.
▪ To pass parameters into functions by reference, append & sign to the
variable.

Program/Solution 1.9 With CLI::

<?php
echo "Enter First number:";
$a=fgets(STDIN);
echo "Enter Second number:";
$b=fgets(STDIN);
echo "Enter Third number:";
$c=fgets(STDIN);
if($a>$b && $a>$c)
echo "$a is greater\n";

SEM-6
I.T. Dept Year 2021 3361603 (WEB DESINGING USING PHP AND MYSQL)

else if($b>$a && $b>$c)


echo "$b is greater\n";
else
echo "$c is greater\n";
?>

Program/Solution 1.9 Without CLI::


<?php
$a=50;
$b=10;
$c=60;
echo("<h1>Maximum of three numbers:</h1>");
if($a>$b){
if($a>$c){
echo("<h2>$a is Maximum</h2>");
}
else{
echo("<h2>$c is Maximum</h2>");
}
}
elseif($b>$c){
echo("<h2>$b is Maximum</h2>");
}
else{
echo("<h2>$c is Maximum</h2>");
}
?>
Output 1.9:
 With CLI:

SEM-6
I.T. Dept Year 2021 3361603 (WEB DESINGING USING PHP AND MYSQL)

 Without CLI:

Program/Solution 1.10:

<?php
function CallByValue($v) //Callby Value
{
$v+=10;
echo 'Value in function ' . $v .'<br>';
}

SEM-6
I.T. Dept Year 2021 3361603 (WEB DESINGING USING PHP AND MYSQL)

function CallByRefrence(&$r) //Callby Refrence


{
echo 'Value in function '. $r+=10 ;
}
$v = 10;
echo '<h2>Call By Value</h2>';
echo 'Value Before Function '. $v . '<br>';
CallByValue($v);
echo 'Value After Function '. $v . '<br>';
echo '<h2>Call By Refrence</h2>';
echo 'Value Before Function '. $v . '<br>';
CallByRefrence($v);
echo '<br>Value After Function '.$v;
?>

Output 1.10:

Program/Solution 1.11:

<?php
echo "<h2> Table of 11</h2>";
for($i=1;$i<=20;$i++){

SEM-6
I.T. Dept Year 2021 3361603 (WEB DESINGING USING PHP AND MYSQL)

echo "11 * $i = " . $i*11 . '<br>';


}
?>

Output 1.11:

Questions:
1. Differentiate call by value Vs call by reference

Call by value Call by reference

A copy of the variable is passed. A variable itself is passed.

Actual and formal arguments will be Actual and formal arguments will be
created in different memory locations. created in the same memory location

With this method, the changes made With this method, using addresses we
to the dummy variables in the called would have access to the actual
function have no effect on the values variables and hence we would be able
of actual variables in the calling to manipulate them.
function.

syntax: function($var){} syntax: function(&$var){}

SEM-6
I.T. Dept Year 2021 3361603 (WEB DESINGING USING PHP AND MYSQL)

1.12 Write PHP Script for addition and multiplication of two 2x2 matrices.
1.13 Write a PHP Script for numeric, Associative and multidimensional arrays.
1.14 Write a PHP script to Find Perimeter and area of rectangle using
parameterized function.
1.15 Write a PHP Script for performing functions that takes arguments, returns
arguments, default argument and variable length argument.
1.16 Write a PHP script to find var args that uses to find max and minimum of
Passed parameters
Software Required: Notepad, WordPad, Notepad++, Dreamweaver,
Wamp/Xampp

Prerequisite: Basic knowledge of editor

Theory/Logic:
l There are mainly two types of arrays:-
1) Indexed/Numeric array. 2) Associative array.
Indexed/Numeric Array:-
l These arrays can store numbers, strings and any object but their index
will be represented by numbers. By default array index starts from 0;
l An array is created using array()
keyword. Syntax:-
$ArrayName=array (value1,
value2...Value); Associative Array:-
l In the Associative array each element has a key associated with it.
l The key can be either numeric or
string. Syntax:-
$ArrayName=array (key1=>value1, key2=>value2...key=>value);
User defined functions:-
l A function is a block of statements that can be used repeatedly in a
program.
l There is no need to declare a function in PHP. You can directly
define function. Syntax:-
Function FunctionName (arguments)
{ //code to be executed;
}

SEM-6
I.T. Dept Year 2021 3361603 (WEB DESINGING USING PHP AND MYSQL)

Function with variable length argument:-


l PHP allows you to pass a variable number of arguments to the function
without defining it.You can just define a function with an empty argument
list and then use one of the following three built in functions.
l func_num_args () — Returns the number of arguments passed to the
function.
l func_get_args (position) — Return the value of the specific argument
specified in position. Position index starts with 0.
l func_get_args () - Returns an array which contains the value of all
arguments passed to the function.
Program/Solution(1.12):

<?php
$a = array(
array(8, 9),
array(5, -1)
);
$b = array(
array(-2, 3),
array(4, 0)
);
echo"<h2>Matrix A:</h2>";
for($i=0;$i<2;$i++){
for($j=0;$j<2;$j++){
echo $a[$i][$j]." | ";
}
echo"<br>";
}
echo"<br>";
echo"<h2>Matrix B:</h2>";
for($i=0;$i<2;$i++){
for($j=0;$j<2;$j++){
echo $b[$i][$j]." | ";
}
echo"<br>";
}
echo"<br>";
echo("<h2>Multiplication of two matrices: </h2><br>");
for($r = 0; $r < 2; $r++){
for($c = 0; $c < 2; $c++){
$e=0;
for($i=0;$i<2;$i++){
$e += $a[$r][$i]*$b[$i][$c];
}
echo $e . ' | ';

SEM-6
I.T. Dept Year 2021 3361603 (WEB DESINGING USING PHP AND MYSQL)

}
echo"<br>";
}
?>

Output(1.12):
Program/Solution(1.13):

<?php
$Lang = array("Flutter", "Android", "Swift");
echo "<h2> One Dimensional Array</h2>";
echo "I like " . $Lang[0] . ", " . $Lang[1] . " and " . $Lang[2] .
".<br>";
$age = array("Raj"=>"35", "Om"=>"37", "Keval"=>"43");
foreach($age as $x => $x_value) {
echo "Key=" . $x . ", Value=" . $x_value;
echo "<br>";
}
echo "<h2> Two Dimensional Array</h2>";
$Lang = array (
array("Flutter",22,18),
array("Android",15,13),
array("Swift",5,2),
array("Kotlin",17,15)
);

for ($row = 0; $row < 4; $row++) {


echo "<p><b>Row number $row</b></p>";
echo "<ol type='1'>";
for ($col = 0; $col < 3; $col++) {
echo "<li>".$Lang[$row][$col]."</li>";
}
echo "</ol>";
}
?>

SEM-6
I.T. Dept Year 2021 3361603 (WEB DESINGING USING PHP AND MYSQL)

Output(1.13):

Program/Solution(1.14):

<?php
function perimeter($l,$b){
return 2*($l+$b);
}
function area($l,$b){
return $l*$b;
}
echo '<h4>Perimeter:</h4> ' .perimeter(10,20) . '<br><h4>Area: </h4>' .
area(10,20);
?>

SEM-6
I.T. Dept Year 2021 3361603 (WEB DESINGING USING PHP AND MYSQL)

Output(1.14):

Program/Solution(1.15):

<?php
function defaultArgs($defaultA = 100,$defaultB=100) {
return $defaultA+$defaultB;
}
function addVarableLength(...$numbers) {
$sum = 0;
foreach ($numbers as $n) {
$sum += $n;
}
return $sum;
}
echo '<h3>pasing parameters argument: </h3>'. defaultArgs(50,50) . '<br>';
echo '<h3>using default argument: </h3>' . defaultArgs() . '<br>';
echo '<h3>varable length argument: </h3>' . addVarableLength(0,1,1,2,3,5,8,13);
?>

SEM-6
I.T. Dept Year 2021 3361603 (WEB DESINGING USING PHP AND MYSQL)

Output(1.15):

Program/Solution(1.16):

<?php
function minMax(...$num){
$max = $num[0];
$min = $num[0];
foreach($num as $n){
if($n>$max){
$max = $n;
}
if($n<$min){
$min=$n;
}
}
return array($max,$min);
}
$minMax = minMax(10,15,10,20,50,5,55,305,255,999);

SEM-6
I.T. Dept Year 2021 3361603 (WEB DESINGING USING PHP AND MYSQL)

echo "<h3>Greatest</h3>";
echo "$minMax[0] <br>";
echo "<h3>Smallest</h3>";
echo "$minMax[1]";
?>

Output(1.16):

Questions:
1 In which situation an associative array is used in PHP?
 associative array have key value pair it can help store some complex
data easily
 For example we have an associative array which contains a user
name password we can give it to access data .
2 Describe user defined function with default argument.
 A function is a block of statements that can be used repeatedly in a
program.
 A function will not execute automatically when a page loads.
 A function will be executed by a call to the function.

SEM-6

You might also like