PHP Tutorial – Functions
The power of the PHP language is the large number of built-in functions (more than 700 built-in function and counting lipitor weight gain.) But of course it also possible to create your own functions. In this PHP tutorial we will create our own functions.
A function will only be executed if a function is called by another piece of code. You can see that this is very handy. For example you can keep the browser from executing a script when the page loads by putting your script into a function. Only when the function is called (for example by pushing a button) the function is executed.
Syntax
function functionName()
{
code to be executed;
}
Some guidelines when creating a PHP function:
- The function name should reflect what the function does.
- The function name can start with an underscore or letter. A number is not allowed.
A Function Example
So let’s look at a function example:
<html>
<body>
<?php
function ourFunction()
{
echo "black";
}
echo "My car has the color ";
ourFunction();
?>
</body>
</html>
The result of this example will be:
My car has the color black
Also look at the next tutorial where we will explain function parameters in PHP programming language.
That is all for this PHP programming tutorials.