ID:               14607
 Comment by:       lev at centers dot ru
 Reported By:      TheWizardRK at yahoo dot com
 Status:           Bogus
 Bug Type:         Scripting Engine problem
 Operating System: Windows 98
 PHP Version:      4.0.6
 New Comment:

I reopen this bag as 22879


Previous Comments:
------------------------------------------------------------------------

[2001-12-22 15:17:41] [EMAIL PROTECTED]

The problem with your script is that nobody has the time to look into
it to understand what is does. If you can't create a real simple
self-contained script which reproduces this bug, it's likely to be an
error in your script, and not in PHP. 

I really think it's a bogus, you're using foreach multiple times which
is messy if you don't reset() at appropriate times.
Reopen if this is not the case.

------------------------------------------------------------------------

[2001-12-20 03:13:51] TheWizardRK at yahoo dot com

$tree = Array(
  [1] => Array ( [parentid] => 0, [name] => '1' )
  [2] => Array ( [parentid] => 0, [name] => '2' )
  [3] => Array ( [parentid] => 1, [name] => '1_1' )
  [4] => Array ( [parentid] => 3, [name] => '1_1_1' )
  [5] => Array ( [parentid] => 3, [name] => '1_1_2' )
  [6] => Array ( [parentid] => 4, [name] => '1_1_1_1' )
  [7] => Array ( [parentid] => 1, [name] => '1_2' )
  [8] => Array ( [parentid] => 7, [name] => '1_2_1' )
  [9] => Array ( [parentid] => 2, [name] => '2_1' )
);

// Recursion using a copy of the variable each time
// WORKS
function funktzia1($base,$dir)
{
  foreach($dir as $id => $item)
  {
    if ($item[parentid]==$base)
    {
      echo
"<UL>\n<LI>".$item[name]."</LI><BR>\n";
      funktzia1($id,$dir);
      echo "</UL>\n";
    }
  }
}

// Print the tree using the first function
funktzia1(0,$tree);


// Recursion using the same variable - pass by reference (note the "&"
before the "$dir")
// DOESN'T WORK
function funktzia2($base,&$dir)
{
  foreach($dir as $id => $item)
  {
    if ($item[parentid]==$base)
    {
      echo
"<UL>\n<LI>".$item[name]."</LI><BR>\n";
      funktzia2($id,$dir);
      echo "</UL>\n";
    }
  }
}

// Print the tree using the second function
funktzia2(0,$tree);

------------------------------------------------------------------------

[2001-12-19 18:31:46] [EMAIL PROTECTED]

Please provide a compelte self-contained copy&paste ready script.

Feedback.

------------------------------------------------------------------------

[2001-12-19 15:17:21] TheWizardRK at yahoo dot com

1. Actually doing a "reset()" doesn't work at all.

2. I thought that this was a duplicate of #5052 - but now I see that
there's too different variables there for each level of the nested
"foreach()" - and I use the same variable.
So it seems that this is not a duplicate after all (corrent me if I'm
wrong).

------------------------------------------------------------------------

[2001-12-19 15:00:55] TheWizardRK at yahoo dot com

It seems that this has been pointed out before... Sorry.
But this is still not solved (although the other bug reports about this
are already marked as "closed"). :(
I only saw a solution of using "reset()" in the end of the loop, but
this doesn't seem to be a good solution.
Any chances that each "foreach()" will be made to work on a new copy of
the array, so that nested "foreach()" will work?

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/14607

-- 
Edit this bug report at http://bugs.php.net/?id=14607&edit=1

Reply via email to