note 72585 added to control-structures.foreach

From: Date: Thu, 25 Jan 2007 09:24:16 +0000
Subject: note 72585 added to control-structures.foreach
Groups: php.notes 
Request: Send a blank email to php-notes+get-122173@lists.php.net to get a copy of this message
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"; } ---- Server IP: 69.147.83.197 Probable Submitter: 201.48.97.43 ---- Manual Page -- http://www.php.net/manual/en/control-structures.foreach.php Edit -- https://master.php.net/note/edit/72585 Del: integrated -- https://master.php.net/note/delete/72585/integrated Del: useless -- https://master.php.net/note/delete/72585/useless Del: bad code -- https://master.php.net/note/delete/72585/bad+code Del: spam -- https://master.php.net/note/delete/72585/spam Del: non-english -- https://master.php.net/note/delete/72585/non-english Del: in docs -- https://master.php.net/note/delete/72585/in+docs Del: other reasons-- https://master.php.net/note/delete/72585 Reject -- https://master.php.net/note/reject/72585 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#122173) next »