#php functions are divided into two types: built-in functions and custom functions.
Recommended reading: php server
##Built-in functions
So-called PHP built-in functions are functions that have been defined in the library of the PHP program, such as echo, mysql_connect, include_once, etc., just like the system functions in VC, such as cout, etc.
In PHP, more than 1,000 built-in functions are provided.
Custom functions
In addition to the built-in PHP functions, we can create our own functions.
- Function is a reusable code block used to complete a specific task in the program;
- Function can make the program more Modular, with good structure;
- After the function is defined, it can be called repeatedly in the program;
- The function will not be executed immediately when the page is loaded. .
- Function will only be executed when called.
Creating user-defined functions in PHP:
User-defined function declarations starting with the word "function":
Syntax
function functionname(){
被执行的代码;
}
Copy after login
Note: Function names can start with letters or underscores (not numbers). Function names are not case sensitive.
Tip: The function name should reflect the task performed by the function.
Example:
We create a function named "shili()". An opening brace ({) indicates the beginning of a function's code, while a closing brace (}) indicates the end of the function. This function outputs "Hello world!". To call this function, just use the function name:
<?php
function shili()
{
each"hello world!";
}
shili();
?>
Copy after login
Output:
hello world!
Copy after login
The above is the detailed content of What are the two types of php functions?. For more information, please follow other related articles on the PHP Chinese website!