What is the usage of php return

藏色散人
Release: 2023-03-08 13:52:02
Original
2348 people have browsed it

php return usage: 1. Return an expression result through the "return expression" syntax; 2. Use the "return(expr)" syntax to return a function expression; 3. Use return to return the value directly.

What is the usage of php return

#The operating environment of this article: Windows7 system, PHP7.1, Dell G3 computer.

Basic usage:

a), return expression // Return an expression result

b), return(expr) // Function expression Formula

c), return // Return directly, or return a null value

Note: It is best not to use return($val).

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

function add($a,$b){
 return $a+$b;
 return $a*$b;
}
Copy after login

$c = add(5,3);//The obtained $c value Can be used elsewhere in the program.

echo $c;
Copy after login

Output result: 8, only $a $b is executed, $a*$b is not executed.

[Recommended: "PHP Video Tutorial"]

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<10";
}
$b=45;
$c=$b-$a;
echo $c;
}
Copy after login

In this example, when you call this function and give it any number, it will return a string, and the code:

$b=45;
$c=$b-$a;
echo $c;
Copy after login

will never be implement.

The above is the detailed content of What is the usage of php return. 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
Popular Tutorials
More>
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!