Little brother just learned PHP a few days not quite understand return is not used to carry back a value in the function of the time used to use it.
See someone in the video today. echo "XXX" in a If statement followed by return
Return is not followed by anything ...
Why not break it here .....
What is the return used in more cases?
Please explain in detail, please, my little brother just get into the function of the big pile also see not very understand please speak of easy to understand some ...
function generally with return, do not write can, write, write a return 1 can also, in fact, there is a little area
As an example,
Saierfunction A () { $b =1; return $b;} Function B () { $b =1; echo $b;} echo a (); output 1b (); Output 1//appear to be output 1, and B () seems to be more convenient, in fact, if you want to use the return value of the function, B () will not be echo a () +1; Output 2//b (); This will not be able to achieve this function, need to go inside the function to change, extension inconvenient
Never understand the use of return when should be used when should not use who can tell? Why add return to the following example?
<?php class man{ private $money =1000; Public function Show () { return $this->money*0.8; }} $a =new man (); Echo $a->show ();? >
Return returns a result to the caller of the function/method.
For instance, your example calls the show () method to return an integer (800). The call is the equivalent of performing 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