note 97640 deleted from class.iteratoriterator by aidan

From: Date: Fri, 30 Apr 2010 04:56:16 +0000
Subject: note 97640 deleted from class.iteratoriterator by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-168800@lists.php.net to get a copy of this message
Note Submitter: aidan at php dot net ---- Unfortunately the documentation for SPL is rather limited at the moment, and some of the methods are not listed. This example demonstrates using the getDepth() method. <?php $tree = array(); $tree[1][2][3] = 'lemon'; $tree[1][4] = 'melon'; $tree[2][3] = 'orange'; $tree[2][5] = 'grape'; $tree[3] = 'pineapple'; print_r($tree); $arrayiter = new RecursiveArrayIterator($tree); $iteriter = new RecursiveIteratorIterator($arrayiter); foreach ($iteriter as $key => $value) { $d = $iteriter->getDepth(); echo "depth=$d k=$key v=$value\n"; } ?> The output of this would be: Array ( [1] => Array ( [2] => Array ( [3] => lemon ) [4] => melon ) [2] => Array ( [3] => orange [5] => grape ) [3] => pineapple ) depth=2 k=3 v=lemon depth=1 k=4 v=melon depth=1 k=3 v=orange depth=1 k=5 v=grape depth=0 k=3 v=pineapple

« previous php.notes (#168800) next »