Home  >  Article  >  Backend Development  >  The concept of php function

The concept of php function

藏色散人
藏色散人Original
2019-08-22 11:38:172353browse

The concept of php function

The concept of php function

PHP user-defined function

● In addition to the built-in PHP functions, we can create our own functions.

● Functions are blocks of statements that can be used repeatedly in a program.

● The function will not be executed immediately when the page is loaded.

● Functions will only be executed when called.

Recommended tutorial: PHP video tutorial

Creating user-defined functions in PHP

User-defined functions are declared with the word " function" starts with:

Syntax

function functionName() {
  被执行的代码;
}

Note: Function names can start with letters or underscores (not numbers).

Note: Function names are not case sensitive.

Tip: The function name should reflect the task performed by the function.

In the following example, we create a function named "writeMsg()". 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:

Instance

Output:

Hello world!

The above is the detailed content of The concept of php function. 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:What does $$ mean in PHP?Next article:What does $$ mean in PHP?