|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2001-01-23 12:09 UTC] cynic@php.net
[2003-11-10 06:28 UTC] giles_m_allen at yahoo dot co dot uk
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 07:00:01 2025 UTC |
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"; else echo "KO<br>\n"; } } $Bar=array(); $Bar[]=new Foo; foreach($Bar as $v) $v->SetOk(); foreach($Bar as $v) $v->EchoOk(); ?> will produce the output : KO<br> I know I can replace the first loop by : foreach($Bar as $k => $v) $Bar[$k]->SetOk(); but, in this case, the $v is useless. I suggest to accept the notation foreach($Arr as &$RefVal) and foreach($Arr as $Key => &$RefVal) in a future PHP release to make $RefVal a reference on each $Arr elements (and not a copy).