Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the use of php return

Shulou Source: shulou.com Published: 2022-06-02 09:47:14 10月02日 Update

The purpose of this article is to share with you about the usage of php return. I think it is very practical, so I share it with you. I hope you can get something after reading this article. Let's take a look at it with the editor.

The use of php return: 1, through the "return expression" way to return an expression result; 2, through the "return (expr)" way to return the function expression; 3, through the return directly return or return null value.

The operating environment of this paper: Windows7 system, PHP7.1, Dell G3.

What is the use of php return?

An Analysis of the usage of return in php

First of all, it means return; return () is a language structure, not a function, and needs to be enclosed in parentheses only if the parameter contains an expression. Parentheses are usually not used when returning a variable, which reduces the burden on PHP.

Basic usage:

A), return expression / / returns an expression result

B), return (expr) / / function expression

C), return / / return directly, or return null

Note: it's best not to use return ($val).

1. If return is executed, the content after the return statement will not be executed

Function add ($a _ r _ r _ b) {return $a _ r _ r _ b; return $a _ r _ r _ b;} $c = add (5j _ 3); / / the resulting $c value can be used elsewhere in the program! Echo $c

Output: 8, only the execution of $astatb is not executed.

2. Return can be a function return value or a null value, depending on the specific usage, for example:

Function test ($a) {if ($a > 10) {return "a > 10";} else {return "a

Tags: Function result output example expression way time that is parenthesis more knowledge article practical important no code function usage content parameters Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Linux Xiaomi NVidia Huawei