Basic structure of PHP functions

韦小宝
Release: 2023-03-17 13:16:02
Original
3209 people have browsed it

php function is particularly commonly used and is easy to reuse and maintain multiple times, so you must understand the basic structure of php function and master php FunctionIt is much simpler to understand the deeper things after the basic structure

The structure of PHP function

Construct a function

function get_sum($a,$b){ 
 $c = $a+$b;  
 return $c;
 }
 $sum = get_sum(3,5) //调用echo $sum; //输出
Copy after login

The basic structure of building a function

  • Keyword: function

  • Function name: get_sum

  • Parameters: ($a,$b)

  • Function body: { $c = $a+$b }

  • Return value: return $c

Function naming rules:

Valid functions must start with letters Or start with an underscore, and can be followed by letters, numbers, or underscores.

The return value of the function:

Definition

  • Value passed The return statement returns

  • can return any type

  • The return statement will immediately terminate the running of the function and transfer control to the calling function Lines of code

Functions are essential knowledge points in PHP. You must master

Related recommendations:

PHP function trim() example

How to use variable quantities in PHP function Detailed explanation of parameter examples

What is the use of the & symbol before the php function

The above is the detailed content of Basic structure of PHP functions. For more information, please follow other related articles on the PHP Chinese website!

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template