递归遍历多维数组(树数据结构)的超级简单方式,并且可以递归超过200层,摘自<>

<?php
$array = array(
"Hello", // Level 1
array(
"World" // Level 2
),
array(
"How", // Level 2
array(
"are", // Level 3
"you" // Level 3
)
),
"doing?" // Level 1
); $recursiveIterator = new RecursiveArrayIterator($array); $recursiveIteratorIterator = new RecursiveIteratorIterator($recursiveIterator); foreach ($recursiveIteratorIterator as $key => $value) {
echo "Depth: " . $recursiveIteratorIterator->getDepth() . PHP_EOL;
echo "Key: " . $key . PHP_EOL;
echo "Value: " .$value . PHP_EOL;
}
?>
上一篇:白帽***与网安工程师教你Kali:跨站脚本***,随便打开一个网站就可能被***控制!


下一篇:Django和Mysql合用时,显示时间问题