Home  >  Article  >  Backend Development  >  Definition of functions in php

Definition of functions in php

angryTom
angryTomOriginal
2019-08-22 13:12:406120browse

Definition of functions in php

A function is to encapsulate a piece of code that is used to complete a specific function. A popular understanding of a function: a block of code that can complete a certain task, just like the building blocks used by children to build a house. It can be used repeatedly. When used, it can be used immediately without considering its internal structure. Below we will introduce to you the definition and use of php functions.

Recommended tutorial: PHP video tutorial

##Custom function

The definition of a function consists of the following four parts:

Keyword function

Function name functionName

Parameter

Function body

	function 函数名([参数1, 参数2, ……]){
	    函数体……
	}

Description of each part

Function: Keywords that must be used when declaring a function

Function name: An identifier that must conform to PHP, and the function name is unique , not case sensitive

[Parameter 1, Parameter 2...]: The value passed to the function from the outside world, it is optional, use commas "," to separate multiple parameters.

Function body: The main body of the function definition, a code segment specifically used to implement a specific function.

Return value: You need to use the return keyword to pass the data to be returned to the caller.

The above is the detailed content of Definition of functions in php. 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