This is a discussion on Recursive function - nothing in return values! within the PHP General forums, part of the PHP Programming Forums category; I am runing into the same kind of problem sometimes.....I have a function but it will NOT return values :-/ ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I am runing into the same kind of problem sometimes.....I have a
function but it will NOT return values :-/ At the moment I am creating a menu-tree where each line in the menu is described by refering to another ID. This way I am able place each menu-line. Note: If you see the "$list" inside function - echo will print everything out fine. BUT if you echo "$pos" inside while-loop I get nothing at all - EXCEPT if there only is 1 occurance. If there are several then this does not work The thing is I have had trouble sometimes that functions does not return values - now I am hoping for a solution - I am looking forward to hear from you all :-) <? /* ------------------- FUNCTION: ------------------- */ function find_pos_back($id, $list, $array_help_all) { $p=0; reset($array_help_all); while($p<count($array_help_all)) { if($array_help_all[$p][HELPID] == "$id") { $id_ref = "".$array_help_all[$p][HELPREFID].""; } $p++; } if($id_ref != "0") { $return_status = "FALSE"; $list_here = "$list,$id_ref"; find_pos_back($id_ref,$list_here, $array_help_all); } else { $return_status = "TRUE"; } if($return_status == "TRUE") { echo "$list"; echo "\n"; return($list); } } /* ---------------- Script calling function ---------------- */ $array_help_all[0][HELPID] = "1"; $array_help_all[0][HELPREFID] = "0"; $array_help_all[1][HELPID] = "2"; $array_help_all[1][HELPREFID] = "1"; $array_help_all[2][HELPID] = "3"; $array_help_all[2][HELPREFID] = "2"; $array_help_all[3][HELPID] = "4"; $array_help_all[3][HELPREFID] = "2"; $array_help_all[4][HELPID] = "5"; $array_help_all[4][HELPREFID] = "1"; $array_help_all[5][HELPID] = "6"; $array_help_all[5][HELPREFID] = "0"; $p=0; reset($array_help_all); while($p<count($array_help_all)) { $id = "".$array_help_all[$p][HELPID].""; $list = "".$array_help_all[$p][HELPID].""; $pos = find_pos_back($id,$list, $array_help_all); $p++; } ?> |