note 52860 deleted from control-structures.foreach by danbrown
| From: | danbrown@php.net | Date: | Tue, 28 Apr 2009 13:10:31 +0000 |
| Subject: | note 52860 deleted from control-structures.foreach by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-153924@lists.php.net to get a copy of this message | ||
Note Submitter: badbrush at pixtur dot de
----
another WARNING about report #26396 having status "wont fix":
Beware of using foreach in recursive functions like...
function sort_folders(&$items, $parent,$level) {
foreach($items as $item) {
if($item->parent == $parent) {
print $item;
// call recursively...
sort_folders(&$items, $item, $level+1);
}
}
}
I struggled a few hours with this code, because I thought the passing the array by reference would
be the problem. Infact you can only have ONE foreach for an array at any given time. A foreach
inside another foreach does not work.
The manual should definately give some hints about this behaviour.
pixtur