|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-09-13 09:51 UTC] jani@php.net
[2007-10-18 05:52 UTC] helly@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 01:00:01 2025 UTC |
Description: ------------ when recursively iterate over recursive array to alter leaves, only first leaves are altered. Reproduce code: --------------- $data = array ('key1' => 'val1', array('key2' => 'val2'), 'key3' => 'val3'); $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($data)); foreach($iterator as $foo) { $key = $iterator->key(); switch($key) { case 'key1': // first level case 'key2': // recursive level echo "update $key<br>"; $iterator->offsetSet($key, 'alter'); } } $copy = $iterator->getArrayCopy(); var_dump($copy); Expected result: ---------------- update key1 update key2 array(3) { ["key1"]=> string(5) "alter" [0]=> array(1) { ["key2"]=> string(4) "alter" } ["key3"]=> string(4) "val3" } Actual result: -------------- update key1 update key2 array(3) { ["key1"]=> string(5) "alter" [0]=> array(1) { ["key2"]=> string(4) "val2" } ["key3"]=> string(4) "val3" }