Recursive Functions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
everydayrun
Forum Commoner
Posts: 51
Joined: Wed Jan 20, 2010 1:30 am

Recursive Functions

Post by everydayrun »

i don't know it very well,only know it return itself.now,i want to know how to use it. and do a deeply understand on it. any tips would be appreciated.
everydayrun
Forum Commoner
Posts: 51
Joined: Wed Jan 20, 2010 1:30 am

Re: Recursive Functions

Post by everydayrun »

anyone helps?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Recursive Functions

Post by VladSun »

Take a look at the recursive definitions of Fibonacci series or factorials for examples:
http://en.wikipedia.org/wiki/Fibonacci_number
http://en.wikipedia.org/wiki/Factorial

In general you need a structure like this:

Code: Select all

function recursive(args, ...)
{
    if (condition_to_stop_rescursion_is_true)
        return (result_to_return_on_recursion_stop);
    else
        return recursive(args_to_be_passed_on_recursive_call);
}
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply