php codeigniter - var_dump shows array but return is null -


so, weird, have method called treetrunk runs parent child relationship , supposed return array if ids "branchpath" - method seems working fine var_dump in terminating condition shows proper array. if try call method returned array "null" - dont it..

model method:

function treetrunk($id){//1st id in page id     if($id == '0'){         var_dump($this->branchpath); //this shows perfect array          return $this->branchpath; //this returns null     }     else{         $q = $this->getwhere(array('id'=>$id),null,null);         array_push($this->branchpath, $q[0]['pageparent']);         $this->treetrunk($q[0]['pageparent']);     }        } 

calling via controller:

$d = $this->pages_mdl->treetrunk('150'); var_dump($d); // <- == null 

var_dump within method outputs "array(3) { [0]=> string(3) "148" [1]=> string(3) "146" [2]=> string(1) "0" } "

you not returning in else part.

else{     $q = $this->getwhere(array('id'=>$id),null,null);     array_push($this->branchpath, $q[0]['pageparent']);     $this->treetrunk($q[0]['pageparent']); }  

should be

else{     $q = $this->getwhere(array('id'=>$id),null,null);     array_push($this->branchpath, $q[0]['pageparent']);     return $this->treetrunk($q[0]['pageparent']); }  

as posted in question passing 150 treetrunk() function, goes else part , gives null result. if part evaluate when pass 0 treetrunk() function.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -