why is it that when i do this, echo does not output the string?
Code:$s = 'string'; return $s; echo $s;
why is it that when i do this, echo does not output the string?
Code:$s = 'string'; return $s; echo $s;
Last edited by ggalan; 05-03-2011 at 11:11 PM.
nm
"If called from within a function, the return() statement immediately ends execution of the current function, and returns its argument as the value of the function call. "
return does two things: 1. it determines the output value for the function; 2. it stops execution of the function at the current point. If you have any complicated structures such as if statements, then it can be difficult to know exactly when the function will end. This can also be useful however:
That is an example of using return as a default value. It acts just like an "else" statement in this case, because if the if statement was true then it would have already exited the function.PHP Code:
function myfunction($x) {
if ($x==true) { return true; }
return false;
}
Note that in your example above it is not within a function, so I don't know what return will do in that situation.
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
ggalan (05-03-2011)
Bookmarks