Never understand the use of return when should be used when should not use who can tell?
Why add return to the following example?
money*0.8; } }$a=new man();echo $a->show();?>
Reply content:
Never understand the use of return when should be used when should not use who can tell?
Why add return to the following example?
money*0.8; } }$a=new man();echo $a->show();?>
return
is to return a result to the caller of the function/method.
For instance, your example calls the show()
method to return an integer (800). The place to call is the equivalent of execution echo 800
.
If your function/method is to perform some operation instead of returning data, you can return a Boolean value to indicate whether the operation succeeded or failed for process control where it was called.
Return what, your function is running out of what, if not return your function is empty after running
For example, function A () {return 1;}
Execute a () to get 1
$b = A (); Then $b is equal to 1, if not return then execute a () there is no return value, that is, empty, that $b is empty