when to use return?
this is a noob question. I'm quite confused sometimes when to use 'return' everytime Im doing my php and javascript codes. Maybe a plain english answer can help me : ) thanks!
rakwel10
Junior Poster in Training
68 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
The "return" statement is used primarily in two areas. One is custom functions that you define and the other is in the include() and require() to return from the required or included page a variable. So here's a sample script.
<?php //index.php
function myfile() {
return 'test.php';
}
$variable=include(myfile());
//$variable now has the value 'test'
<?php //test.php
return 'test';
?>
As you can see in that script is all of the uses for return. Basically it ends the subscript and returns to the parent script.
cwarn23
Occupation: Genius
3,033 posts since Sep 2007
Reputation Points: 413
Solved Threads: 259