JackJones
153
12
General

Help with recursion

Posted 9 months ago by JackJones

Is there a way to not have to pass an intended returned variable back into a function?

function do_this($a, $to_return = [])
{
    // do some stuff

    if(condition) {
               return do_this($a, $to_return);
    }

    return $to_return;
}

I'm trying to get away from having to pass $to_return into the function at all

It isn't the end of the world but it looks a bit odd putting it it

Please sign in or create an account to participate in this conversation.