PHP function

PHP User Define Function

In Computer programming some time a specific piece of work done more then one time at different places when you need. For this purpose we use Function. A function is block of statements which are written as separate from the other code and execute when we need it by calling this function. You can use these function over and over when you need it.

How we write The Function In PHP

In PHP first of all the function is declare with keyword Function. After the keyword Function we write The Function name. Every function must have a unique name and then each function have a body with some statement. body start with { and end with }. The actual statements of function written in between these curly brackets.
Now we take a n simple example to understand the function.
If you want to display the Title of you webpage many time between your other contents then you can do with the help of function.
The code below is practical example of above task


function display_title()

 {

echo  "This is LearningHints.com";

}

Calling a function in PHP
Now You can use this function when ever you need in your page by calling this function.

echo "this is simple code" ."<br />";

display_title( );

echo "this is simple code" ."<br />";

echo "this is simple code" ."<br />";

display_title( );