| PHP Functions |
| |
| Creating and using simple functions |
| |
| The first step in creating a PHP function is provide a name by which you will reference the function. Naming conventions for PHP functions are the same as those for variables in that they must begin with a letter or an underscore and must be devoid of any kind of white space or punctuation. You must also take care to ensure that your function name does not conflict with any of the PHP built in functions. |
| |
| PHP functions are created using the function keyword followed by the name and, finally, a set of parentheses. The body of the function (the script that performs the work of the function) is then enclosed in opening and closing braces. |
| |
| The following example function simply outputs a string when it is called: |
| |
<?php
function sayHello()
{
print "Hello";
}
?>
<hr>
<center><h3>PHP Function Demo</h3></center>
<hr>
<?php
sayHello();
?>
|
| |
| Save the above script as simplefunction.php and open the page in browser to view the output. |
| |
 |
| |
| |
|
| |
| |