Web Technologies
Functions in PHP
Smt.M.Jeevana Sujitha
Assistant Professor
Department of Computer Science and Engineering
SRKR Engineering College, Bhimavaram, A.P. - 534204
OBJECTIVES
The Objective of this lecture is
Functions
Creating user defined function:
and all the php code should be put inside curly braces.
Syntax:
function function-name(par-list)
{
Code to be executed;
}
Example:
<?php
function display() //called function
{
echo "welcome to php functions";
}
display(); // calling function
?>
Functions
PHP function arguments:
parentheses.
with a comma.
Example:
<?php
function add($a, $b) //called function
{
echo $a+$b;
}
add(10,20); // calling function
?>
Functions
PHP default arguments:
Example:
<?php
function setHeight($height=50) //called function
{
echo $height;
}
setHeight(200); // calling function setHeight();
?>
Functions
Dynamic Function calls:
Example:
<?php
function display() //called function
{
echo “haiii”;
}
$show=“display”
show(); //calling function
?>
THANK YOU