note 18116 deleted from language.references by sniper

From: Date: Tue, 30 Sep 2003 01:17:51 +0000
Subject: note 18116 deleted from language.references by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-57304@lists.php.net to get a copy of this message
Note Submitter: ken@nospam.notenetwork.com ---- You may be looking for how to iterate over an array by reference. For example, you have an array of objects, and you want to call methods that modify the objects. A normal foreach doesn't work, as the elements of the array are copied. each() doesn't work either. You have to use a for loop. Example of what *COPIES* objects (not what you probably want): foreach($object_list as $object) { $object->method(); } Example of what does not copy objects (probably what you want): for ($c = 0; $c = count($object_list); $c++) { $object = &$object_list[$c]; $object->method(); } You get the picture.

« previous php.notes (#57304) next »