Re: Possible foreach bug; seeking advice to isolate the problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 20 Oct 2010 08:37:55 +0200, php-general@xxxxxxxxxxxxxxx (Gary)
wrote:

>Better. I can tell you how to solve it:
>    $a = array('a', 'b','c');
>    foreach($a as &$row){
>        //you don't have to do anything here
>    }
>    unset($row); // <----<<< THIS IS KEY!
>    print_r($a);
>    foreach($a as $row){
>        echo "<br />".$row;
>    }
>    print_r($a);

I don't quite I follow this. I'll have to try it when I have time (I
hope later today) to understand what you're proposing.

Unfortunately it won't work in this, for one or two reasons.

The first possible reason is that I'm not referencing the "as"
variable with an ampersand. If I'd have to add one to fix this
problem, it might cause other problems.

The second (definite) reason is that I can't read the array
destructively (with an unset). The problem occurs in code that is
preparing the array for later read-only use, so that would be
self-defeating!

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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux