note 18116 added to language.references
| From: | ken at nospam dot notenetwork dot com | Date: | Fri, 11 Jan 2002 00:44:29 +0000 |
| Subject: | note 18116 added to language.references | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-24645@lists.php.net to get a copy of this message | ||
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.
--
http://www.php.net/manual/en/language.references.php
http://master.php.net/manage/user-notes.php?action=edit+18116
http://master.php.net/manage/user-notes.php?action=delete+18116
http://master.php.net/manage/user-notes.php?action=reject+18116