This code I have written and understood. The idea came to me when I tried to solve it with a "for" loop.
Is that a "clean code"? I've heard about recursion many times, but until now I didn't call the function again and again, because the thing with the "Allowed memory size" without the if-block scared me! 👻
A recursive function is a function that calls itself. If the function keeps calling itself, how does it know when to stop? You have to set up a condition, known as a base case. Base cases tell our recursive call when to stop, otherwise it will loop infinitely.
@michaloravec How will my function keep looping infinitely? The condition is already set. It works just fine. And there is no difference between his and mine function, I just wrote it in less lines.
"I've heard about recursion many times, but until now I didn't call the function again and again, because the thing with the "Allowed memory size" without the if-block scared me!"
If I don't catch an error somewhere, it will crash on a live server, but it will not paralyze it. But if I start an "infinite call", it will crash much more, right?
I actually believe that it is xdebug that catches it :) You can give it a try on your local testing environment. Without xdebug you would most likely just run out of memory and the thread would be closed.