PHP - User Defined Function

PHP function is a piece of code that can be reused many times. It can take input as argument list and return value. 

There are thousands of built-in functions in PHP.

PHP allows you to create user-defined functions, where you can create your functions. A function is a collection of statements that can be used over and over again in a program. A call to a function will cause it to be run. There are several built-in functions in PHP, such as mathematical, string, date, and array functions. A function can also be defined to meet a specific requirement. The term “user-defined function” refers to such a function. A function does not run when it is defined; instead, it runs when it is called.

Syntax

function functionname(){  

//code to be executed  

}  

Example

function sayHello(){  

echo "Hello PHP Function";  

}  

sayHello();//calling function  

?>  

We can pass the information in PHP function through arguments which is separated by comma.

PHP supports Call by Value (default), Call by Reference, Default argument values and Variable-length argument list.