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

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

    Best explanation I have found when I was learning that myself is here:http://www.elated.com/articles/php-recursive-functions/

    Its because one thing:

    The function when its called is created in memory (new instance is created)

    So the recursive function IS NOT CALLLING ITSELF, but its calling other instance - so its not one function in memory doing some magic. Its couple of instances in memory which are returning themselves some values - and this behavior is the same when for example function a is calling function b. You have two instances as well as if recursive function called new instance of itself.

    Try draw memory with instances on paper - it will make sense.

提交回复
热议问题