PHP includes over 1,000 built-in functions that can be called directly from a script to execute specific tasks.
In addition to built-in PHP functions, you can also create your own functions.
A user-defined function declaration begins with the keyword function, followed by the function’s name:
function |
Note: A function name must begin with a letter or an underscore. Function names are NOT case-sensitive. |
Tip: Choose a function name that clearly indicates its purpose!
To invoke the function, simply write its name followed by parentheses ():
function
|
In our example, we define a function called myMessage().
The opening curly brace { marks the start of the function code, while the closing curly brace signifies the end of the function.
The function prints “Hello world!”.