SlideShare a Scribd company logo
Introduction to PHP
Lecture 10
Table of
Content
1.What is PHP Arrays
2.Types of Arrays in PHP
3. DifferentTypes of Loops in PHP
4. PHP Functions
5. GET Method
6. POST Method
1.Whatis
PHPArrays
Arrays are complex variables that allow us to
store more than one value or a group of values
under a single variable name. Let's suppose you
want to store colors in your PHP script. Storing
the colors one by one in a variable could look
something like this:
<?php
$color1 = "Red";
$color2 = "Green";
$color3 = "Blue";
?>
There are three types of arrays that you can
create. These are:
 Indexed array — An array with a numeric key.
 Associative array — An array where each key
has its own specific value.
 Multidimensional array — An array
containing one or more arrays within itself.
2.Typesof
Arraysin
PHP
<!DOCTYPE html>
<html lang="en">
<head>
<title>PHP Indexed Arrays</title>
</head>
<body>
<?php
$colors = array("Red", "Green",
"Blue");
// Printing array structure
print_r($colors);
?>
</body>
</html>
Output:
Array ( [0] => Red [1] => Green [2] => Blue)
Example
onIndexed
Array
<!DOCTYPE html>
<html lang="en">
<head>
<title>PHP Indexed Arrays</title>
</head>
<body>
<?php
$colors[0] = "Red";
$colors[1] = "Green";
$colors[2] = "Blue";
// Printing array structure
print_r($colors);
?>
</body>
</html>>
Thisis
equivalenttothe
following
example,in
whichindexes
areassigned
manually:
 In an associative array, the keys assigned to values
can be arbitrary and user defined strings. In the
following example the array uses keys instead of
index numbers:
Associative
Arrays
<!DOCTYPE html>
<html lang="en">
<head>
<title>PHP Associative Array</title>
</head>
<body>
<?php
$ages = array("Peter"=>22, "Clark"=>32, "John"=>28);
// Printing array structure
print_r($ages);
?>
</body>
</html>
Output:
Array ( [Peter] => 22 [Clark] => 32 [John] => 28 )
Exampleon
Associative
Array
 The multidimensional array is an array in which each element
can also be an array and each element in the sub-array can be an
array or further contain array within itself and so on. An
example of a multidimensional array will look something like
this:
Multidimensional
Arrays
<body>
<?php
// Define nested array
$contacts = array(
array(
"name" => "Peter Parker",
"email" => "peterparker@mail.com",
),
array(
"name" => "Clark Kent",
"email" => "clarkkent@mail.com",
),
array(
"name" => "Harry Potter",
"email" => "harrypotter@mail.com",
)
);
// Access nested value
echo "Peter Parker's Email-id is: " . $contacts[0]["email"];
?>
Output:
Peter Parker's Email-id is: peterparker@mail.com
Exampleon
Multidimensional
Array
Loops are used to execute the same block of code again and again, as long as a
certain condition is met. The basic idea behind a loop is to automate the
repetitive tasks within a program to save the time and effort. PHP supports
four different types of loops.
 while — loops through a block of code as long as the condition specified
evaluates to true.
 do…while — the block of code executed once and then condition is
evaluated. If the condition is true the statement is repeated as long as the
specified condition is true.
 for — loops through a block of code until the counter reaches a specified
number.
 foreach — loops through a block of code for each element in an array.
 You will also learn how to loop through the values of array
using foreach() loop at the end of this chapter. The foreach() loop work
specifically with arrays.

DifferentTypes
ofLoopsin
PHP
The while statement will loops through a block of code as long as the
condition specified in the while statement evaluate to true.
while(condition){
// Code to be executed
}
Internt applications-Lecture 11
PHPwhile
Loop
The example below define a loop that starts with $i=1. The loop will continue to
run as long as $i is less than or equal to 3. The $i will increase by 1 each time the
loop runs:
<!DOCTYPE html>
<html lang="en">
<head>
<title>PHP while Loop</title>
</head>
<body>
<?php
$i = 1;
while($i <= 3){
$i++;
echo "The number is " . $i . "<br>";
}
?>
</body>
</html>
Output:
The number is 2
The number is 3
The number is 4
PHPwhileLoop
Example
The do-while loop is a variant of while loop, which evaluates the condition at
the end of each loop iteration. With a do-while loop the block of code
executed once, and then the condition is evaluated, if the condition is true,
the statement is repeated as long as the specified condition evaluated to is
true.
do{
// Code to be executed
}
while(condition);
PHPdo…while
Loop
<!DOCTYPE html>
<html lang="en">
<head>
<title>PHP do-while Loop</title>
</head>
<body>
<?php
$i = 1;
do{
$i++;
echo "The number is " . $i . "<br>";
}
while($i <= 3);
?>
</body>
</html>
PHPdo-while
Loop
Example
Output:
The number is 2
The number is 3
The number is 4
The for loop repeats a block of code as long as a certain condition is met. It is
typically used to execute a block of code for certain number of times.
for(initialization; condition; increment){
// Code to be executed
}
The parameters of for loop have following meanings:
 initialization — it is used to initialize the counter variables, and evaluated
once unconditionally before the first execution of the body of the loop.
 condition — in the beginning of each iteration, condition is evaluated. If it
evaluates to true, the loop continues and the nested statements are executed.
If it evaluates to false, the execution of the loop ends.
 increment — it updates the loop counter with a new value. It is evaluate at the
end of each iteration.
PHPforLoop
<!DOCTYPE html>
<html lang="en">
<head>
<title>PHP for Loop</title>
</head>
<body>
<?php
for($i=1; $i<=3; $i++){
echo "The number is " . $i . "<br>";
}
?>
</body>
</html>
Output:
The number is 2
The number is 3
The number is 4
PHPForLoop
Example
The foreach loop is used to iterate over arrays.
foreach($array as $value){
// Code to be executed
}
PHPforeach
Loop
<!DOCTYPE html>
<html lang="en">
<head>
<title>PHP foreach Loop</title>
</head>
<body>
<?php
$colors = array("Red", "Green", "Blue");
// Loop through count array
foreach($colors as $value){
echo $value . "<br>";
}
?>
</body>
</html>
Output:
Red
Green
Blue
PHPforeachLoop
Example
<?php
$superhero = array(
"name" => "Peter Parker",
"email" => "peterparker@mail.com",
"age" => 18
);
// Loop through superhero array
foreach($superhero as $key => $value){
echo $key . " : " . $value . "<br>";
}
?>
</body>
</html>
Output:
name : Peter Parker
email : peterparker@mail.com
age : 18
PHPforeachLoop
Example
 A function is a self-contained block of code that performs a specific
task.
 PHP has a huge collection of internal or built-in functions that you
can call directly within your PHP scripts to perform a specific task,
like gettype(), print_r(), var_dump, etc.
Internt applications-Lecture 11
PHPFunctions
1.PHPBuilt-in
Functions
In addition to the built-in functions, PHP also allows you to define your own
functions. It is a way to create reusable code packages that perform specific
tasks and can be kept and maintained separately form main program. Here
are some advantages of using functions:
 Functions reduces the repetition of code within a program — Function
allows you to extract commonly used block of code into a single component.
Now you can perform the same task by calling this function wherever you
want within your script without having to copy and paste the same block of
code again and again.
 Functions makes the code much easier to maintain — Since a function
created once can be used many times, so any changes made inside a
function automatically implemented at all the places without touching the
several files.
 Functions makes it easier to eliminate the errors —When the program is
subdivided into functions, if any error occur you know exactly what function
causing the error and where to find it.Therefore, fixing errors becomes
much easier.
 Functions can be reused in other application — Because a function is
separated from the rest of the script, it's easy to reuse the same function in
other applications just by including the php file containing those functions.
2.PHPUser-
Defined
Functions
The basic syntax of creating a custom function can be give with:
function functionName(){
// Code to be executed
}
The declaration of a user-defined function start with the
word function, followed by the name of the function you want to
create followed by parentheses i.e. () and finally place your
function's code between curly brackets {}.
Creatingand
Invoking
Functions
You can specify parameters when you define your function to accept input
values at run time. The parameters work like placeholder variables within a
function; they're replaced at run time by the values (known as argument)
provided to the function at the time of invocation.
function myFunc($oneParameter, $anotherParameter){
// Code to be executed
}
You can define as many parameters as you like. However for each parameter
you specify, a corresponding argument needs to be passed to the function
when it is called.
Functionswith
Parameters
<?php
// Defining function
function getSum($num1, $num2){
$sum = $num1 + $num2;
echo "Sum of the two numbers $num1 and $num2 is : $sum";
}
// Calling function
getSum(10, 20);
?>
</body>
</html>
Output:
Sum of the two numbers 10 and 20 is : 30
Functionswith
Parameters
<?php
// Defining function
function divideNumbers($dividend, $divisor){
$quotient = $dividend / $divisor;
$array = array($dividend, $divisor, $quotient);
return $array;
}
// Assign variables as if they were an array
list($dividend, $divisor, $quotient) = divideNumbers(10, 2);
echo $dividend . "<br>"; // Outputs: 10
echo $divisor . "<br>"; // Outputs: 2
echo $quotient . "<br>"; // Outputs: 5
?>
</body>
</html>
Output:
10
2
5
Functionswith
Parameters
<?php
/* Defining a function that multiply a number
by itself and return the new value */
function selfMultiply(&$number){
$number *= $number;
return $number;
}
$mynum = 5;
echo $mynum . "<br>"; // Outputs: 5
selfMultiply($mynum);
echo $mynum . "<br>"; // Outputs: 25
?>
</body>
</html>
Output:
5
25
Functionswith
Parameters
Get
Method
Get
Method
Get
Method
Get
Method
Get
Method
Get
Method
Get&Post
Method
Post
Method
Post
Method
Post
Method
Post
Method
Post
Method
Post
Method
PHP Lec 2.pdfsssssssssssssssssssssssssss

More Related Content

PPTX
Introduction to PHP_ Lexical structure_Array_Function_String
PPTX
PHP FUNCTIONS AND ARRAY.pptx
PPTX
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
PPT
PHP - Web Development
PDF
lab4_php
PDF
lab4_php
PDF
Lecture14-Introduction to PHP-coding.pdf
Introduction to PHP_ Lexical structure_Array_Function_String
PHP FUNCTIONS AND ARRAY.pptx
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
PHP - Web Development
lab4_php
lab4_php
Lecture14-Introduction to PHP-coding.pdf

Similar to PHP Lec 2.pdfsssssssssssssssssssssssssss (20)

PPTX
unit 1.pptx
PDF
Programming in PHP Course Material BCA 6th Semester
PPT
PHP Fuctions.ppt,IT CONTAINS PHP INCLUDE FUNCTION
PPT
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
PPT
Php i basic chapter 3
PPT
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
PPTX
php basics
PPTX
The basics of php for engeneering students
PPTX
Php.ppt
PDF
PHP Reviewer
PPTX
Introduction to php
DOC
php&mysql with Ethical Hacking
PPT
PHP-03-Functions.ppt
PPT
PHP-03-Functions.ppt
PPTX
FYBSC IT Web Programming Unit IV PHP and MySQL
PDF
How to run PHP code in XAMPP.docx (1).pdf
PPTX
object oriented programming in PHP & Functions
PPT
Introduction To Php For Wit2009
unit 1.pptx
Programming in PHP Course Material BCA 6th Semester
PHP Fuctions.ppt,IT CONTAINS PHP INCLUDE FUNCTION
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
php basics
The basics of php for engeneering students
Php.ppt
PHP Reviewer
Introduction to php
php&mysql with Ethical Hacking
PHP-03-Functions.ppt
PHP-03-Functions.ppt
FYBSC IT Web Programming Unit IV PHP and MySQL
How to run PHP code in XAMPP.docx (1).pdf
object oriented programming in PHP & Functions
Introduction To Php For Wit2009
Ad

More from ksjawyyy (9)

PPTX
Week(2)CH1.pptxjssssssssssssssssssssjjjjjjj
PPTX
Week(1)CH1.pptxs5s5sssss5s55ssssssssssss
PDF
Dr. Thanaa Lecture 1.pdfssssssssssssssss
PDF
3. lecture 8 javascriptno.pdssssssssssssf
PDF
lecture 7- Java Intro.pdfsssssssssssssss
PDF
presentation1-160wwqqqecdds705022717.pdf
PDF
presentation1-1607050227ddasas17 (1).pdf
PPT
kei_iqsensato_presentation_e.ppttttttttt
PDF
Java Script 2nd lec.pdfsssssssssssssssss
Week(2)CH1.pptxjssssssssssssssssssssjjjjjjj
Week(1)CH1.pptxs5s5sssss5s55ssssssssssss
Dr. Thanaa Lecture 1.pdfssssssssssssssss
3. lecture 8 javascriptno.pdssssssssssssf
lecture 7- Java Intro.pdfsssssssssssssss
presentation1-160wwqqqecdds705022717.pdf
presentation1-1607050227ddasas17 (1).pdf
kei_iqsensato_presentation_e.ppttttttttt
Java Script 2nd lec.pdfsssssssssssssssss
Ad

Recently uploaded (20)

PDF
DuckDuckGo Private Browser Premium APK for Android Crack Latest 2025
PDF
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
PDF
Wondershare Recoverit Full Crack New Version (Latest 2025)
PPTX
GSA Content Generator Crack (2025 Latest)
PDF
EaseUS PDF Editor Pro 6.2.0.2 Crack with License Key 2025
PPTX
Custom Software Development Services.pptx.pptx
PDF
DNT Brochure 2025 – ISV Solutions @ D365
PPTX
Advanced SystemCare Ultimate Crack + Portable (2025)
PPTX
chapter 5 systemdesign2008.pptx for cimputer science students
PDF
Salesforce Agentforce AI Implementation.pdf
PPTX
Why Generative AI is the Future of Content, Code & Creativity?
PDF
Complete Guide to Website Development in Malaysia for SMEs
PPTX
Trending Python Topics for Data Visualization in 2025
DOCX
Greta — No-Code AI for Building Full-Stack Web & Mobile Apps
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PPTX
Oracle Fusion HCM Cloud Demo for Beginners
PDF
STL Containers in C++ : Sequence Container : Vector
PDF
AI/ML Infra Meetup | LLM Agents and Implementation Challenges
PPTX
Weekly report ppt - harsh dattuprasad patel.pptx
PDF
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
DuckDuckGo Private Browser Premium APK for Android Crack Latest 2025
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
Wondershare Recoverit Full Crack New Version (Latest 2025)
GSA Content Generator Crack (2025 Latest)
EaseUS PDF Editor Pro 6.2.0.2 Crack with License Key 2025
Custom Software Development Services.pptx.pptx
DNT Brochure 2025 – ISV Solutions @ D365
Advanced SystemCare Ultimate Crack + Portable (2025)
chapter 5 systemdesign2008.pptx for cimputer science students
Salesforce Agentforce AI Implementation.pdf
Why Generative AI is the Future of Content, Code & Creativity?
Complete Guide to Website Development in Malaysia for SMEs
Trending Python Topics for Data Visualization in 2025
Greta — No-Code AI for Building Full-Stack Web & Mobile Apps
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
Oracle Fusion HCM Cloud Demo for Beginners
STL Containers in C++ : Sequence Container : Vector
AI/ML Infra Meetup | LLM Agents and Implementation Challenges
Weekly report ppt - harsh dattuprasad patel.pptx
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...

PHP Lec 2.pdfsssssssssssssssssssssssssss

  • 2. Table of Content 1.What is PHP Arrays 2.Types of Arrays in PHP 3. DifferentTypes of Loops in PHP 4. PHP Functions 5. GET Method 6. POST Method
  • 3. 1.Whatis PHPArrays Arrays are complex variables that allow us to store more than one value or a group of values under a single variable name. Let's suppose you want to store colors in your PHP script. Storing the colors one by one in a variable could look something like this: <?php $color1 = "Red"; $color2 = "Green"; $color3 = "Blue"; ?>
  • 4. There are three types of arrays that you can create. These are:  Indexed array — An array with a numeric key.  Associative array — An array where each key has its own specific value.  Multidimensional array — An array containing one or more arrays within itself. 2.Typesof Arraysin PHP
  • 5. <!DOCTYPE html> <html lang="en"> <head> <title>PHP Indexed Arrays</title> </head> <body> <?php $colors = array("Red", "Green", "Blue"); // Printing array structure print_r($colors); ?> </body> </html> Output: Array ( [0] => Red [1] => Green [2] => Blue) Example onIndexed Array
  • 6. <!DOCTYPE html> <html lang="en"> <head> <title>PHP Indexed Arrays</title> </head> <body> <?php $colors[0] = "Red"; $colors[1] = "Green"; $colors[2] = "Blue"; // Printing array structure print_r($colors); ?> </body> </html>> Thisis equivalenttothe following example,in whichindexes areassigned manually:
  • 7.  In an associative array, the keys assigned to values can be arbitrary and user defined strings. In the following example the array uses keys instead of index numbers: Associative Arrays
  • 8. <!DOCTYPE html> <html lang="en"> <head> <title>PHP Associative Array</title> </head> <body> <?php $ages = array("Peter"=>22, "Clark"=>32, "John"=>28); // Printing array structure print_r($ages); ?> </body> </html> Output: Array ( [Peter] => 22 [Clark] => 32 [John] => 28 ) Exampleon Associative Array
  • 9.  The multidimensional array is an array in which each element can also be an array and each element in the sub-array can be an array or further contain array within itself and so on. An example of a multidimensional array will look something like this: Multidimensional Arrays
  • 10. <body> <?php // Define nested array $contacts = array( array( "name" => "Peter Parker", "email" => "peterparker@mail.com", ), array( "name" => "Clark Kent", "email" => "clarkkent@mail.com", ), array( "name" => "Harry Potter", "email" => "harrypotter@mail.com", ) ); // Access nested value echo "Peter Parker's Email-id is: " . $contacts[0]["email"]; ?> Output: Peter Parker's Email-id is: peterparker@mail.com Exampleon Multidimensional Array
  • 11. Loops are used to execute the same block of code again and again, as long as a certain condition is met. The basic idea behind a loop is to automate the repetitive tasks within a program to save the time and effort. PHP supports four different types of loops.  while — loops through a block of code as long as the condition specified evaluates to true.  do…while — the block of code executed once and then condition is evaluated. If the condition is true the statement is repeated as long as the specified condition is true.  for — loops through a block of code until the counter reaches a specified number.  foreach — loops through a block of code for each element in an array.  You will also learn how to loop through the values of array using foreach() loop at the end of this chapter. The foreach() loop work specifically with arrays.  DifferentTypes ofLoopsin PHP
  • 12. The while statement will loops through a block of code as long as the condition specified in the while statement evaluate to true. while(condition){ // Code to be executed } Internt applications-Lecture 11 PHPwhile Loop
  • 13. The example below define a loop that starts with $i=1. The loop will continue to run as long as $i is less than or equal to 3. The $i will increase by 1 each time the loop runs: <!DOCTYPE html> <html lang="en"> <head> <title>PHP while Loop</title> </head> <body> <?php $i = 1; while($i <= 3){ $i++; echo "The number is " . $i . "<br>"; } ?> </body> </html> Output: The number is 2 The number is 3 The number is 4 PHPwhileLoop Example
  • 14. The do-while loop is a variant of while loop, which evaluates the condition at the end of each loop iteration. With a do-while loop the block of code executed once, and then the condition is evaluated, if the condition is true, the statement is repeated as long as the specified condition evaluated to is true. do{ // Code to be executed } while(condition); PHPdo…while Loop
  • 15. <!DOCTYPE html> <html lang="en"> <head> <title>PHP do-while Loop</title> </head> <body> <?php $i = 1; do{ $i++; echo "The number is " . $i . "<br>"; } while($i <= 3); ?> </body> </html> PHPdo-while Loop Example Output: The number is 2 The number is 3 The number is 4
  • 16. The for loop repeats a block of code as long as a certain condition is met. It is typically used to execute a block of code for certain number of times. for(initialization; condition; increment){ // Code to be executed } The parameters of for loop have following meanings:  initialization — it is used to initialize the counter variables, and evaluated once unconditionally before the first execution of the body of the loop.  condition — in the beginning of each iteration, condition is evaluated. If it evaluates to true, the loop continues and the nested statements are executed. If it evaluates to false, the execution of the loop ends.  increment — it updates the loop counter with a new value. It is evaluate at the end of each iteration. PHPforLoop
  • 17. <!DOCTYPE html> <html lang="en"> <head> <title>PHP for Loop</title> </head> <body> <?php for($i=1; $i<=3; $i++){ echo "The number is " . $i . "<br>"; } ?> </body> </html> Output: The number is 2 The number is 3 The number is 4 PHPForLoop Example
  • 18. The foreach loop is used to iterate over arrays. foreach($array as $value){ // Code to be executed } PHPforeach Loop
  • 19. <!DOCTYPE html> <html lang="en"> <head> <title>PHP foreach Loop</title> </head> <body> <?php $colors = array("Red", "Green", "Blue"); // Loop through count array foreach($colors as $value){ echo $value . "<br>"; } ?> </body> </html> Output: Red Green Blue PHPforeachLoop Example
  • 20. <?php $superhero = array( "name" => "Peter Parker", "email" => "peterparker@mail.com", "age" => 18 ); // Loop through superhero array foreach($superhero as $key => $value){ echo $key . " : " . $value . "<br>"; } ?> </body> </html> Output: name : Peter Parker email : peterparker@mail.com age : 18 PHPforeachLoop Example
  • 21.  A function is a self-contained block of code that performs a specific task.  PHP has a huge collection of internal or built-in functions that you can call directly within your PHP scripts to perform a specific task, like gettype(), print_r(), var_dump, etc. Internt applications-Lecture 11 PHPFunctions 1.PHPBuilt-in Functions
  • 22. In addition to the built-in functions, PHP also allows you to define your own functions. It is a way to create reusable code packages that perform specific tasks and can be kept and maintained separately form main program. Here are some advantages of using functions:  Functions reduces the repetition of code within a program — Function allows you to extract commonly used block of code into a single component. Now you can perform the same task by calling this function wherever you want within your script without having to copy and paste the same block of code again and again.  Functions makes the code much easier to maintain — Since a function created once can be used many times, so any changes made inside a function automatically implemented at all the places without touching the several files.  Functions makes it easier to eliminate the errors —When the program is subdivided into functions, if any error occur you know exactly what function causing the error and where to find it.Therefore, fixing errors becomes much easier.  Functions can be reused in other application — Because a function is separated from the rest of the script, it's easy to reuse the same function in other applications just by including the php file containing those functions. 2.PHPUser- Defined Functions
  • 23. The basic syntax of creating a custom function can be give with: function functionName(){ // Code to be executed } The declaration of a user-defined function start with the word function, followed by the name of the function you want to create followed by parentheses i.e. () and finally place your function's code between curly brackets {}. Creatingand Invoking Functions
  • 24. You can specify parameters when you define your function to accept input values at run time. The parameters work like placeholder variables within a function; they're replaced at run time by the values (known as argument) provided to the function at the time of invocation. function myFunc($oneParameter, $anotherParameter){ // Code to be executed } You can define as many parameters as you like. However for each parameter you specify, a corresponding argument needs to be passed to the function when it is called. Functionswith Parameters
  • 25. <?php // Defining function function getSum($num1, $num2){ $sum = $num1 + $num2; echo "Sum of the two numbers $num1 and $num2 is : $sum"; } // Calling function getSum(10, 20); ?> </body> </html> Output: Sum of the two numbers 10 and 20 is : 30 Functionswith Parameters
  • 26. <?php // Defining function function divideNumbers($dividend, $divisor){ $quotient = $dividend / $divisor; $array = array($dividend, $divisor, $quotient); return $array; } // Assign variables as if they were an array list($dividend, $divisor, $quotient) = divideNumbers(10, 2); echo $dividend . "<br>"; // Outputs: 10 echo $divisor . "<br>"; // Outputs: 2 echo $quotient . "<br>"; // Outputs: 5 ?> </body> </html> Output: 10 2 5 Functionswith Parameters
  • 27. <?php /* Defining a function that multiply a number by itself and return the new value */ function selfMultiply(&$number){ $number *= $number; return $number; } $mynum = 5; echo $mynum . "<br>"; // Outputs: 5 selfMultiply($mynum); echo $mynum . "<br>"; // Outputs: 25 ?> </body> </html> Output: 5 25 Functionswith Parameters