On Sat, 23 Oct 2010 08:34:27 +0200, [email protected] (Peter
Lind) wrote:
>It is not a bug - somewhere before the foreach loop you've got, a
>variable is being referenced, and that's throwing things off.
>Otherwise, unsetting the variable would have no effect on the problem
>you're seeing.
Could you please be more specific? "Somewhere... a variable is being
referenced" doesn't give me any insight into what is happening.
It's absolutely clear to me WHERE the problem is. The first foreach
loop is causing the problem; I can prove this by removing it. But WHAT
the problem is, is absolutely unclear. I've studied this code every
which way, and I don't see how the first foreach loop can possibly
make the second one change the array -- unless it's a bug.
I've boiled the script down to a couple of dozen lines that
demonstrate the problem without references to a database or to other
scripts. Having this to play with may help others give me some
insight.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head> <title>foreach problem</title> </head>
<body>
<?php
$qs = array();
for ($i=0; $i<3; ++$i) {
$qs[] = array($i);
}
foreach ($qs as &$q) {
}
echo $qs[0][0] . $qs[1][0] . $qs[2][0] . "<br>";
foreach ( $qs as $q ) {
echo $qs[0][0] . $qs[1][0] . $qs[2][0] . "<br>";
}
echo $qs[0][0] . $qs[1][0] . $qs[2][0] . "<br>";
?>
</body>
</html>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php