Home > Article > Backend Development > What is the usage of php return
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.
#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; }
$c = add(5,3);//The obtained $c value Can be used elsewhere in the program.
echo $c;
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; }
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;
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!