note 104588 modified in arrayiterator.offsetunset by danbrown

From: Date: Fri, 24 Jun 2011 15:02:33 +0000
Subject: note 104588 modified in arrayiterator.offsetunset by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-180911@lists.php.net to get a copy of this message
Make sure you use this function to unset a value. You can't access this iterator's values as an array. Ex: <?php $iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($arr)); foreach($iterator as $key => $value) { unset($iterator[$key]); } ?> Will return : PHP Fatal error: Cannot use object of type RecursiveIteratorIterator as array offsetUnset works properly even when removing items from nested arrays. --was-- Make sure you use this function to unset a value. You can't access this iterator's values as an array. Ex: $iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($arr)); foreach($iterator as $key => $value) { unset($iterator[$key]); } Will return : PHP Fatal error: Cannot use object of type RecursiveIteratorIterator as array offsetUnset works properly even when removing items from nested arrays. http://php.net/manual/en/arrayiterator.offsetunset.php

« previous php.notes (#180911) next »