PHP Function Create
In this chapter you will learn:
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 j a va 2 s . 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.
Next chapter...
What you will learn in the next chapter:
- What is PHP Function Parameter
- Syntax for PHP Function Parameter
- Example - Add parameter to a function
Home » PHP Tutorial » PHP Function Create