php - Variable inside recursive function change in for-loop -



php - Variable inside recursive function change in for-loop -

i have variable argument of recursive function, , value alter in code without warning. echo $idparent before , in for, , value different.

public function sortcategoriesbylevel($categories, $levelmax, $idparent, $currentlevel = 0) { $sortedcategories = array(); $categoriesfiltered = array(); //here don't understand : echo ' idparent sent fonction : '.$idparent; //output id for($i = 0; $i < count($categories); $i++) { echo '<br /> idparent in "for" : '; var_dump($idparent); //output -1 no matter what!!!! echo '<br /> isset idparent : '; echo isset($idparent); $level = $categories[$i]->level; echo '<br /> run <br />'; if($level == $currentlevel) { echo '<br /> traitement <br />'; $id = $categories[$i]->id; echo 'idparent before status : '.$idparent.' id : '.$id; if($idparent == $id || $idparent == -1) { $sortedcategories[$currentlevel][$categories[$i]->id][0] = $categories[$i]; echo '<br /> enregistrement <br />'; } else { echo '<br /> sauvegarde <br />'; $categoriesfiltered[] = $categories[$i]; } /*echo '<br />'; var_dump($categoriesfiltered); echo '<br />';*/ if($currentlevel < $levelmax) { echo '<br /> appel <br />'; $currentlevel++; $sortedcategories[$currentlevel][$categories[$i]->id][1][] = $this->sortcategoriesbylevel($categoriesfiltered, $levelmax, $id, $currentlevel); } } } homecoming $sortedcategories; }

the result is:

idparent sent fonction : -1 idparent in "for" : int(-1) isset idparent : 1 run

traitement idparent before status : -1 id : 18 enregistrement

appel idparent sent fonction : 18 idparent in "for" : int(-1) isset idparent : 1 run

i have set in bold part don't understand.

php recursion

Comments

Popular posts from this blog

java Multi query from Mysql using netbeans -

c# - DotNetZip fails with "stream does not support seek operations" -

c++ - StartServiceCtrlDispatcher don't can access 1063 error -