note 104175 added to control-structures.foreach

From: Date: Mon, 30 May 2011 02:59:32 +0000
Subject: note 104175 added to control-structures.foreach
Groups: php.notes 
Request: Send a blank email to php-notes+get-180090@lists.php.net to get a copy of this message
There's a gotcha with this. If you are iterating across an array of objects (not arrays), you will be modifying the actual object! $things = array(new stdClass(), new stdClass()); foreach ($things as $thing) { $thing->magic = TRUE; } print_r($things); This will output an array of objects, each with magic=TRUE! ---- Server IP: 69.147.83.197 Probable Submitter: 118.209.134.181 ---- Manual Page -- http://www.php.net/manual/en/control-structures.foreach.php Edit -- https://master.php.net/note/edit/104175 Del: integrated -- https://master.php.net/note/delete/104175/integrated Del: useless -- https://master.php.net/note/delete/104175/useless Del: bad code -- https://master.php.net/note/delete/104175/bad+code Del: spam -- https://master.php.net/note/delete/104175/spam Del: non-english -- https://master.php.net/note/delete/104175/non-english Del: in docs -- https://master.php.net/note/delete/104175/in+docs Del: other reasons-- https://master.php.net/note/delete/104175 Reject -- https://master.php.net/note/reject/104175 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#180090) next »