Using return statement you can returned the values to calling function.
Using return statement in function is optional as we see in our previous chapters.
You can return any type of data including arrays and objects.
A function can not return multiple values.
When PHP see return in function, it cause ends of execution of function immediately and pass control to the line from which it was called.
For example:
1 2 3 4 5 6 7 |
function add($a,$b) { $c = $a + $b; return $c; } echo "Addition of two values is " . add(2,6); ?> |
Output
1 |
Addition of two values is 8 |
In above example function add() return value of $c from it is called.