Welcome to my series on every PHP keyword and its usage. Today’s item: return.

The return keyword ends the current scope, and optionally passes a value back to the calling scope. It can be used inside of functions/methods, and in the global scope.

When used inside a function, the function will finish and the result will be passed back to the caller.

When used inside the global scope, it will end the current script. If the script was included from another script, the result will be passed back to the calling script.

Usage

1
2
3
4
5
6
7
8
9
<?php
function return7()
{
	return 7;
}

$seven = return7();

return $seven;