Recursion result passing
in
Programming Questions
•
2 years ago
I hope no one minds the PHP short hand. Its just so much less restrictive then writing things like this in Java first. I am having trouble devising the method to pass the result of this function back out. I understand what is happening because the subsequent calls to recursion_trigger() solve in reverse order but can not wrap my head around passing the result back up the stack = / Is there a proper way to do this.
The function is straight forward pass it an array it pops an element of and then increments count then calls it self intill the array is empty.
- function recursion_trigger($input, $count = 0){
- if(!empty($input)){
- array_pop($input);
- $count++;
- if(!empty($input)){
- recursion_trigger($input,$count);
- }
- }
- echo $count;
- return $count;
- }
1