Skip to content

Instantly share code, notes, and snippets.

@Raensul
Created January 16, 2018 18:08
Show Gist options
  • Save Raensul/4d90061030fe6bc8aede798f9413497e to your computer and use it in GitHub Desktop.
Save Raensul/4d90061030fe6bc8aede798f9413497e to your computer and use it in GitHub Desktop.
<?php
$arr = array(
3, 4, 5,
[5, 7, 8,
[9, 10, 11, 12,
[13, 14, 15],
15, 17],
18, 19],
20
);
$rit = new RecursiveArrayIterator($arr);
echo "<pre>";
//var_dump($rit);
$rii = new RecursiveIteratorIterator($rit);
echo "<hr>";
echo "RecursiveArrayIterator<br>";
foreach ($rii as $key => $value) {
$depth = $rii->getDepth();
echo " depth = $depth, key = $key, value = $value<br>";
}
echo "<hr>";
echo "foreach<br>";
foreach ($arr as $key => $value) {
echo "key = $key, value = $value<br>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment