Recursive function - nothing in return values!

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 :-/ ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-12-2005
Nikolaj Schulz
 
Posts: n/a
Default Recursive function - nothing in return values!

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++;
}


?>
Reply With Quote
  #2 (permalink)  
Old 05-21-2005
paulroskilly@hotmail.com
 
Posts: n/a
Default Re: Recursive function - nothing in return values!

Hi,

For one thing :

$array_help_all[0][HELPID]

should be : $array_help_all[0]["HELPID"]

What are you trying to do anyway, go backwards thru an array?


Paul

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 02:27 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0