note 105812 deleted from recursiveiteratoriterator.getsubiterator by danbrown

From: Date: Fri, 16 Sep 2011 20:38:17 +0000
Subject: note 105812 deleted from recursiveiteratoriterator.getsubiterator by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-183226@lists.php.net to get a copy of this message
Note Submitter: mike dot mackintosh at angrystatic dot com ---- Here is a great example found on stackoverflow posted by jared: // I changed your input example to make it harder and // to show it works at lower depths: $arr = array(0 => array('id'=>1,'name'=>"cat 1"), 1 => array(array('id'=>3,'name'=>"cat 1")), 2 => array('id'=>2,'name'=>"cat 2") ); //here's the code: $arrIt = new RecursiveIteratorIterator(new RecursiveArrayIterator($arr)); foreach ($arrIt as $sub) { $subArray = $arrIt->getSubIterator(); if ($subArray['name'] === 'cat 1') { $outputArray[] = iterator_to_array($subArray); }

« previous php.notes (#183226) next »