Definition of functions in php

angryTom
Release: 2023-04-07 08:48:01
Original
6137 people have browsed it

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, ……]){ 函数体…… }
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!