ID: 8373
Comment by: giles_m_allen at yahoo dot co dot uk
Reported By: ocomte at guarantycity dot com
Status: Duplicate
Bug Type: Feature/Change Request
Operating System: All
PHP Version: 4.0.4
New Comment:

I Agree, it would be usefull, it there any way in which you can force
it to pass by reference as it is?

Previous Comments:

[2001-01-23 12:09:21] [email][/email]

dupe of #3074

btw, +1 for foreach( $a as &$v ) :)


[2000-12-22 05:47:53] ocomte at guarantycity dot com

It would be very useful (at least for me) if the fonction foreach
support references. For example the code :
class Foo
{ var $Ok=false;
function EchoOk()
{ if ($this->Ok)
echo "OK<br>\n";
echo "KO<br>\n";

$Bar[]=new Foo;
foreach($Bar as $v)
foreach($Bar as $v)
will produce the output :

I know I can replace the first loop by :
foreach($Bar as $k => $v)
but, in this case, the $v is useless.

I suggest to accept the notation
foreach($Arr as &$RefVal)
foreach($Arr as $Key => &$RefVal)
in a future PHP release to make $RefVal a reference on each $Arr
elements (and not a copy).


Edit this bug report at [url][/url]