note 73631 added to language.references.whatdo

From: Date: Mon, 05 Mar 2007 06:56:07 +0000
Subject: note 73631 added to language.references.whatdo
Groups: php.notes 
Request: Send a blank email to php-notes+get-124091@lists.php.net to get a copy of this message
I discovered something today using references in a foreach <?php $a1 = array('a'=>'a'); $a2 = array('a'=>'b'); foreach ($a1 as $k=>&$v) $v = 'x'; echo $a1['a']; // will echo x foreach ($a2 as $k=>$v) {} echo $a1['a']; // will echo b (!) ?> After reading the manual this looks like it is meant to happen. But it confused me for a few days! (The solution I used was to turn the second foreach into a reference too) ---- Server IP: 203.220.0.234 Probable Submitter: 210.15.202.115 ---- Manual Page -- http://www.php.net/manual/en/language.references.whatdo.php Edit -- https://master.php.net/note/edit/73631 Del: integrated -- https://master.php.net/note/delete/73631/integrated Del: useless -- https://master.php.net/note/delete/73631/useless Del: bad code -- https://master.php.net/note/delete/73631/bad+code Del: spam -- https://master.php.net/note/delete/73631/spam Del: non-english -- https://master.php.net/note/delete/73631/non-english Del: in docs -- https://master.php.net/note/delete/73631/in+docs Del: other reasons-- https://master.php.net/note/delete/73631 Reject -- https://master.php.net/note/reject/73631 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#124091) next »