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

前端 未结 16 1317
庸人自扰
庸人自扰 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:32

    Recursion is an alternative to loops, it's quite seldom that they bring more clearness or elegance to your code. A good example was given by Progman's answer, if he wouldn't use recursion he would be forced to keep track in which directory he is currently (this is called state) recursions allows him to do the bookkeeping using the stack (the area where variables and return adress of a method are stored)

    The standard examples factorial and Fibonacci are not useful for understanding the concept because they're easy to replace by a loop.

提交回复
热议问题