PHP Function Create
Description
We define functions with the function keyword, followed by the name of the function and two parentheses.
The actual code your function will execute lies between braces.
Syntax
Defining a function use the following syntax:
function myFunc() {
// (do stuff here)
}
Example
Define a function
<?PHP/*from w w w . ja v a 2s . c om*/
function hello() {
echo "Hello, world!\n";
}
hello();
?>
The code above generates the following result.
As you can see, this script defines a function, hello() , that simply displays the string "Hello, world! "
The code within the hello() function is only run when the function is later called, not when the function itself is created.