What does function mean in php

藏色散人
Release: 2023-02-28 14:14:01
Original
10865 people have browsed it

What does function mean in php

What does function mean in php?

function is a keyword used to declare user-defined functions.

The syntax structure of PHP declaration function

Function function_name($argument1,$argument2,$argument3,......$argumentn) { //函数代码code Return 返回值; }
Copy after login

Among them:

function_name: The name of the function to be created. This name will be used when it is called later. The function name should be unique, Because PHP does not support overloading. When naming functions, you need to follow the same principles as variable naming

. However, the function name cannot start with $, but the variable can.

argument: to be passed The value given to the function. The function can have multiple parameters, with commas between them. But the parameter items are optional and you can not pass any parameters when calling the function.

code: is when the function is called A piece of code that is executed when. If there are two or more statements, the code must be enclosed in curly braces "{}". However, if there is only one code, curly braces are not required.

Return: Returns the value required by the calling code. Any type can be returned, including lists and objects. This causes the function to immediately end its execution and pass control back to the line on which it was called.

Examples include:

function jia($a) { $b = $a+10; return $b; }
Copy after login

The above is a custom function, let’s see how to use it

echo jia('10');
Copy after login

The displayed result is 20

Here jia is the custom function name, so just give $ The result returned by any number is 10. This is a customized function. This example is very simple~ But by customizing the function, you will find that everything becomes better.

Recommended: "PHP Tutorial"

The above is the detailed content of What does function mean in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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!