PHP » Control Structures » return

Syntax:
return [value]
value
Value to return to the caller.

Returns a value to the caller.

Functions and scripts included with the include() or require() functions can return a value to the caller using the return statement. The use of return means that the execution of the script or function stops.

Examples

Code:
<?php

function formatText($s) {
   $s = "<b><i>" . $s . "</b></i>";
   return $s;
}

$text = "Some random text";
$text = formatText($text);
print htmlSpecialChars($text);

?>
Output:
<b><i>Some random text</b></i>
Explanation:

A function that formats text is defined. It adds some html tags to a string and returns the result in a return statement.

See Also: