The following example shows how to call jj () in this case, why does one still print out null? it seems that the return value of the function is not used here. if I call this function, I just need to execute it to print $? Why are you still following... the following example shows how to call jj () in this case, why does one still print out null? it seems that the return value of the function is not used here. if I call this function, I just need to execute it to print $? Why is it related to the return value?
function jj(){ $a=1; echo $a; } $b=jj(); var_dump($b);
Reply content:
The following example shows how to call jj () in this case, why does one still print out null? it seems that the return value of the function is not used here. if I call this function, I just need to execute it to print $? Why is it related to the return value?
function jj(){ $a=1; echo $a; } $b=jj(); var_dump($b);
Print is only displayed on the screen. if you use this value, you must use return to receive it elsewhere. So here your function does not return anything, just prints 1, so variable B does not get any value, so it is null.
Because your function does not have a return statement, null is returned after execution.
Your function execution process:
$ B = jj (); call jj () to assign a value to $ a, print $ a, No Return (return is null)
Var_dump $ B, $ B is assigned the return value of jj (), so it is null
After the execution is complete, the printed values 1 ($ a value) and null ($ B value) are left)
function jj(){ $a=1; echo $a; return $a; } $b=jj(); var_dump($b);
This is the expected output.
Your jj function directly outputs $ a without return, so $ B is empty.
$ B = jj (); // output 1 directly calls the jjvar_dump ($ B) function; // output the null print function? The result after the return value is not used: 1D: \ WWW \ demo. php: 15: int 1
Echo is the direct output, and return returns the location where it is called.