PHP return Statement

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

PHP return Statement


PHP return statement immediately terminates the execution of a function when it is called from within that function.

This function is also used to terminate the execution of an eval() function or script file.

If this function is called from a global scope, the function stops the execution of the current script. If the current script file was included using include() or required(), then control goes back to the calling file.


return expression

Where expression is any valid expression. Note that, since the return is not a function but a language construct, using parenthesis is not required.

Return values


Return value

If called from within a function

Returns the argument of the function.

If the current script file was included using include() or required()

Value given to return().

If no parameter is supplied

NULL is returned.


Example :

Code of p.php

  1. include("q.php");  

  2. echo "p";  

  3. ?>  

Code of q.php

  1. echo "q";  

  2. return;  

  3. ?>  

View the output of p.php

View the output of q.php

See also

continue, break