Home  >  Article  >  Backend Development  >  What are the two types of php functions?

What are the two types of php functions?

尚
Original
2019-10-21 10:21:243366browse

What are the two types of php functions?

#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(){
    被执行的代码;
}

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();
?>

Output:


hello world!

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to make a php pageNext article:How to make a php page