Function in PHP
Function in PHP
Definition
Functions are the group of statements that you can execute as a single unit. Function
definations are the lines of code that make up a function.
The syntax for defining a function is:
<?php
<?php
function say_hello() {
echo “<p>Hello everybody!</p>”;
}
say_hello();
Function writeMSg() {
Echo “How are You?”;
}
writeMsg();
?>
Example:
User defined function with one argument:
<?php
function familyName($fname)
{
echo "$fname Refsnes.<br>";
}
familyName("Jani");
familyName("Hege");
familyName("Kai Jim");
familyName("Borge");
?>
Php default argument value
If we call the function setHeight() without arguments it takes the default value as argument:
Example:
<?php
function setHeight($minheight=50)
{
echo "The height is : $minheight <br>";
}
setHeight(350);
setHeight(); // will use the default value of 50
setHeight(135);
setHeight(80);
?>