return

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() will also end the execution of an eval() statement or script file.

If called from the global scope, then execution of the current script file is ended. If the current script file was include()ed or require()ed, then control is passed back to the calling file. Furthermore, if the current script file was include()ed, then the value given to return() will be returned as the value of the include() call. If return() is called from within the main script file, then script execution ends. If the current script file was named by the auto_prepend_file or auto_append_file configuration options in php.ini, then that script file's execution is ended.

For more information, see Returning values.

Замечание: Note that since return() is a language construct and not a function, the parentheses surrounding its arguments are not required. It is common to leave them out, and you actually should do so as PHP has less work to do in this case.

Замечание: You should never use parentheses around your return variable when returning by reference, as this will not work. You can only return variables by reference, not the result of a statement. If you use return ($a); then you're not returning a variable, but the result of the expression ($a) (which is, of course, the value of $a).

Коментарии

for those of you who think that using return in a script is the same as using exit note that: using return just exits the execution of the current script, exit the whole execution.

look at that example:

a.php
<?php
include("b.php");
echo 
"a";
?>

b.php
<?php
echo "b";
return;
?>

(executing a.php:) will echo "ba".

whereas (b.php modified):

a.php
<?php
include("b.php");
echo 
"a";
?>

b.php
<?php
echo "b";
exit;
?>

(executing a.php:) will echo "b".
2005-12-18 14:28:44
http://php5.kiev.ua/manual/ru/function.return.html
Автор:
Note that because PHP processes the file before running it, any functions defined in an included file will still be available, even if the file is not executed.

Example:

a.php
<?php
include 'b.php';

foo();
?>

b.php
<?php
return;

function 
foo() {
     echo 
'foo';
}
?>

Executing a.php will output "foo".
2013-06-25 23:11:55
http://php5.kiev.ua/manual/ru/function.return.html

    Поддержать сайт на родительском проекте КГБ