i

PHP Tutorial

Returning Values From A Function

Functions have the capability to return a value when they are called. To return the values, we use the return keyword for functions. This keyword returns the value back to the program where the function is called, and it may be of any data type. A return statement is the last statement in the function code, and it stops the execution and returns the value to the program.

For example, – If we want a function to get the result of multiplication of two numbers multiple times in a program, we can create a multiply function with two arguments as below and return the values.

function Multiply($num1, $num2)

{

           $result=$num1 * $num2 ;

           return $result;

}

$product = Multiply(4,5);

echo “ The result is $product”;

?>