Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Recursive Function

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 102
    Comment on it

    A function that call itself is known as *Recursive Function*. Recursive function keeps calling itself. We have to set a condition that will stop it, otherwise it will run infinitely. This condition is known as a base case. Basically, base case tells the recursive function when to stop. One such example of recursive function is to find out factorial of a number n.

    function fact($num) {
      if ($num === 0) { // our base case which stop the recursive function
         return 1;
      }
      else {
         return $num * fact($num-1); // calling itself.
      }
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: