Re: Odd behavior
| From: | jekillen | Date: | Mon, 25 Dec 2006 17:09:49 +0000 |
| Subject: | Re: Odd behavior | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-246211@lists.php.net to get a copy of this message | ||
On Dec 25, 2006, at 7:21 AM, Roman Neuhauser wrote:
# jekillen@prodigy.net / 2006-12-24 18:11:03 -0800: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)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 oneThe 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
{
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