How to use Function-return value in PHP

In this article, I will explain how the Function-return value can be used in PHP.
  • 2902

Function-return value in PHP

  • A function can return a value using the return statement in conjunction with a value or object.

  • In return value function, return keyword is used to return a value from a function.

  • In return value function, return stops the execution of the function and sends the value back to the calling code.


 function functionname(parameters)


  code to be executed;

  return value



The following example takes two integer parameters and add them together and then returns their total.



<title>Function which returns value</title>



<h2 style="color: steelblue;">Function with return value example</h2>


    function add($num1, $num2)


    $total = $num1 + $num2;

    return $total;


    $return_value = add(50, 70);

    echo "Returned value from the function : $return_value";







You may also want to read these related articles here
Ask Your Question 
Got a programming related question? You may want to post your question here
© 2020 DotNetHeaven. All rights reserved.