What in layman's terms is a Recursive Function using PHP

前端 未结 16 1329
庸人自扰
庸人自扰 2020-11-22 05:50

Can anyone please explain a recursive function to me in PHP (without using Fibonacci) in layman language and using examples? i was looking at an example but the Fibonacci to

16条回答
  •  滥情空心
    2020-11-22 06:41

    Basically this. It keeps calling itself until its done

    void print_folder(string root)
    {
        Console.WriteLine(root);
        foreach(var folder in Directory.GetDirectories(root))
        {
            print_folder(folder);
        }
    }
    

    Also works with loops!

    void pretend_loop(int c)
    {
        if(c==0) return;
        print "hi";
        pretend_loop(c-);
    }
    

    You can also trying googling it. Note the "Did you mean" (click on it...). http://www.google.com/search?q=recursion&spell=1

提交回复
热议问题