Search the Community
Showing results for tags 'recursive function'.
-
I have a recursive function which is calling a recursive funtion. The 2nd recursive function have a weird issue, because when I use return-statement it returns to the function itself (probably because that is where it is originated) - so any suggestions to how I secure coming back to main function? Here is the code I am currently working on........ function display_children($arrIn) { global $arrContentGlobal; # retrieve all children of $parent $sql1 = " SELECT * FROM formulaTree WHERE versionId='$arrIn[versionId]' AND criterionId='$arrIn[criterionId]' AND formulaTreeIdRef='$arrIn[parentId]' "; $res1 = mysql_query("$sql1"); $num1 = mysql_num_rows($res1); while($obj = mysql_fetch_array($res1)) { # Find level -> run other function (THIS IS HERE PROBLEM STARTS.....) $arrInLevel[formulaTreeId] = "$obj[formulaTreeId]"; $arrLevel = displayFathers($arrInLevel); # Go for this function again............ $arrIn[parentId] = "$obj[formulaTreeId]"; display_children($arrIn); } } function displayFathers($arrIn) { if(!$arrIn[level]) { $arrIn[level] = 0; } $sqlChild = "SELECT * FROM formulaTree WHERE formulaTreeId='$arrIn[formulaTreeId]'"; $resChild = mysql_query("$sqlChild"); $objChild = mysql_fetch_array($resChild); $arrConceptsId[] = "$objChild[formulaTreeIdRef]"; if($objChild[formulaTreeIdRef] != "0") { $arrIn[level]++; $arrIn[formulaTreeId] = "$objChild[formulaTreeIdRef]"; displayFathers($arrIn); } $arrOut[level] = $arrIn[level]; return($arrOut); }