- <?php
- // 遍历一个多维数组,得到它们的目录关系
- $tree = array
- (
- 'common.lua',
- 'prototype.lua',
- 'round' => array
- (
- 'AI.lua',
- 'creature' => array
- (
- 'boy.lua'
- ),
- 'round.lua',
- 'trump' => array
- (
- 'firefan.lua',
- 'mirror.lua'
- )
- )
- );
- function iterate($data, $pre="")
- {
- if (is_array($data))
- {
- foreach($data as $key => $item)
- {
- if(is_array($item)) {
- $pre .= $key."/";
- iterate($item, $pre);
- $pre = substr($pre, 0, strpos($pre, $key)); //回退到上层目录
- }
- else
- {
- echo $pre.$item."\\n";
- }
- }
- }
- }
- iterate($tree);
- ?>
- //该片段来自于http://www.codesnippet.cn/detail/2904201512447.html
来源: http://www.codesnippet.cn/detail/2904201512447.html