PHP Function Return

In this chapter you will learn:

  1. What is function return
  2. Note for function return
  3. Example - return value from a function

Description

Function can return one value back from functions by using the return statement.

Note

If you try to assign to a variable the return value of a function that has no return value, your variable will be set to NULL.

Example

Return value from a function


<?PHP//ja  v  a  2 s .  com
function foo() { 
       print "In function"; 
       return 1; 
       print "Leaving function..."; 
} 
print foo(); 
?>

The code above generates the following result.

Next chapter...

What you will learn in the next chapter:

  1. How to return a reference
  2. Syntax to return reference from a function
  3. Example - Return reference from a function
Home » PHP Tutorial » PHP Function Create
PHP Function
PHP Function Create
PHP Function Parameter
PHP Function Default Parameters
PHP Variable Length Parameter
PHP Function Reference Parameter
PHP Function Return
PHP Return Reference
PHP Variable Scope in Functions
PHP Global Variables
PHP Recursive Functions
PHP Anonymous Function
PHP static variable