递归函数Codeigniter

When I try to call this function in the URL as I am working in CI, www.example.com/tree/get_parent/3432/1

It gives me 1 instead of 1,2,3,4. I don't know what the problem in that code? I don't know why it doesn't call itself 4 times

public function get_parent($id,$n) {
if($n==5){ return 1; }

else { echo $n;
$n++; return get_parent($id,$n);
} }

Any help is really appreciated. thanks

looks like your not calling the right method, try:

return $this->get_parent($id,$n);

Just take out the return in the else statement

public function get_parent($id,$n) {
    if($n==5){ return 1; }

    else { 
        echo $n;
        $n++;
        get_parent($id,$n);
    } 
}