note 104586 added to arrayiterator.offsetunset

From: Date: Fri, 24 Jun 2011 06:14:34 +0000
Subject: note 104586 added to arrayiterator.offsetunset
Groups: php.notes 
Request: Send a blank email to php-notes+get-180914@lists.php.net to get a copy of this message
A very important thing to note about \RecursiveIteratorIterator is that it returns a flattened array when used with the iterator_to_array function. Ex: //[CODE START] $arr = array('Zero', 'name'=>'Adil', 'address' => array( 'city'=>'Dubai', 'tel' => array('int' => 971, 'tel'=>12345487)), '' => 'nothing'); $iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($arr)); var_dump(iterator_to_array($iterator,true)); //[CODE END] This code will return : array(6) { [0]=> string(4) "Zero" ["name"]=> string(4) "Adil" ["city"]=> string(5) "Dubai" ["int"]=> int(91) ["tel"]=> int(12345487) [""]=> string(7) "nothing" } To get the non-flattened proper array use the getArrayCopy() method, like so : $iterator->getArrayCopy() This will return array(4) { [0]=> string(4) "Zero" ["name"]=> string(4) "Adil" ["address"]=> array(2) { ["city"]=> string(5) "Dubai" ["tel"]=> array(2) { ["int"]=> int(91) ["tel"]=> int(12345487) } } [""]=> string(7) "nothing" } ---- Server IP: 202.65.157.132 Probable Submitter: 122.181.21.94 ---- Manual Page -- http://www.php.net/manual/en/arrayiterator.offsetunset.php Edit -- https://master.php.net/note/edit/104586 Del: integrated -- https://master.php.net/note/delete/104586/integrated Del: useless -- https://master.php.net/note/delete/104586/useless Del: bad code -- https://master.php.net/note/delete/104586/bad+code Del: spam -- https://master.php.net/note/delete/104586/spam Del: non-english -- https://master.php.net/note/delete/104586/non-english Del: in docs -- https://master.php.net/note/delete/104586/in+docs Del: other reasons-- https://master.php.net/note/delete/104586 Reject -- https://master.php.net/note/reject/104586 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#180914) next »