note 72585 deleted from control-structures.foreach by danbrown

From: Date: Tue, 28 Apr 2009 13:04:57 +0000
Subject: note 72585 deleted from control-structures.foreach by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-153907@lists.php.net to get a copy of this message
Note Submitter: joaohbruni at yahoo dot com dot br ---- Iterate through an array of objects, and change property values from original object. My original code only worked in PHP5: foreach($array as $element) { $element->property = "new_value"; } Solution for both PHP4 and PHP5: reset($array); while (list($key, $value) = each($array)) { $element =& $array[$key]; $element->property = "new_value"; }

« previous php.notes (#153907) next »