Advise a good article about recursion in php. I studied it in js, but in view of the uselessness I somehow forgot about it, and I think there are some differences.

I am interested in as many details as possible, but the main thing is that the topic of limiting the number of calls to recursion was raised.

  • 2
    Recursion as recursion, is limited by memory and this notorious Stack Overflow. - KAGG Design
  • What happens when the stack overflows? And what is this number? - Shillkas
  • the program is completed, and the memory is released - Cyril

2 answers 2

Recursive functions

<?php function recursion($a) { if ($a < 20) { echo "$a\n"; recursion($a + 1); } } ?> 

Note : A recursive call of methods / procedures with a depth of more than 100-200 levels of recursion can cause stack overflow and cause a script to crash. In particular, infinite recursion will be considered a software error.

Source: tyk
PS: Scroll through 4 examples.

    From the point of view of the theory, I most liked the life metaphor of recursion, when you take the mirror in your hands and stand facing the other mirror. As a result, you can see a reflection of yourself with a mirror, and in this mirror another reflection :)