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

What are the two types of php functions?

青灯夜游
青灯夜游Original
2019-10-19 11:27:103020browse

What are the two types of php functions?

The real power of PHP comes from its functions. Functions are divided into built-in functions and custom functions.

Built-in functions

The 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.

● Functions are reusable blocks of code used to complete a specific task in the program;

● Functions can make the program more modular and have a 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 begin with the words "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 "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!". If you need to call this function, just use the function name:

<?php
function sayhi() {
   echo "Hello world!";
}

sayhi();
?>

Output:

Hello world!

For more PHP-related knowledge, please visit php中文网!

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