On Dec 25, 2006, at 7:21 AM, Roman Neuhauser wrote:

# [EMAIL PROTECTED] / 2006-12-24 18:11:03 -0800:
function display($list, $in, $out, $save, $req, $x)
 {
      for($i = 0; $i < count($in); $i++)
      {$j = $i + 1;
      // two sets of links displayed instead of one
         for($i = 0; $i < count($out); $i++)
          {$j = $i + 1;
            // two sets of links displayed instead of one
          for($i = 0; $i < count($save); $i++)
           {$j = $i + 1;
             // two sets of links displayed instead of one
          for($i = 0; $i < count($req); $i++)
           {$j = $i + 1;
             // two sets of links displayed instead of one

The print lines above are supposed to produce a list of links to files.
In the web display I get duplicate sets of links which seems to mean
that the loops in the function are running twice, and in one instance
three times instead of once.

Look at the variable names you use for iteration.

Thanks, Usually, when a variable name like $i is used and then
reset to 0 in the next loop it does not matter. But I solved the
problem and posted the solution.  I also solved the regex
problem. There was an extra \n sneaking into the test pattern
so I could not get a match. I am not sure where the extra \n is
coming from.
It looks like I didn't post the solution after all:
Update:
I solved the double loops problem with this code change:

function display($list, $a, $x)
                {
                 for($i = 0; $i < count($a); $i++)
                    {$j = $i + 1;
print "<a href=\"steps.php?list=$list&next=$j&x=$x\">$j</a><br><br>\n";
                    };
                 }
and:

if($list || $current)
  {
    switch($list)
          {
           case 'in':
           display($list, $in, $x);
           break;
           case 'out':
           display($list, $out, $x);
           break;
           case 'save':
           display($list, $save, $x);
           break;
           case 'req':
           display($list, $req, $x);
           break;
          }
  }
Apparently what was happening was that the code running under 5.1.2
was trying to process all the arrays that had values in spite of the switch statement in the original display() function. If the was an $in array the switch would process that for the $list value being 'in' but since there
was also a save value, the switch tried to process it also, even though
'save' wasn't the $list value. I found it would do this for all arrays that
had values. So if three had values the loop selected loop would run
three times.
Could this be a bonafide bug?
JK

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to