You are here: Recursive function - nothing in return values! « PHP « IT news, forums, messages
Recursive function - nothing in return values!

Posted by Nikolaj Schulz on 05/12/05 10:30

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


?>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация