我写了一个,通过它我想要一个包含所有和的php function
数组。files
directories
directory
1)下面是我的目录结构 -
/pages (Full path - /home/ubuntu/projects/xyz.com/code/ciapp/views/pages)
|
|--file1.php
|--file2.php
|--file3.php
|--folder1
|--file4.php
|--file5.php
|--folder2
|--file6.php
|--folder3
|--file7.php
|--file8.php
2)我想要的array
是files and directories
-
Array
(
[files] => Array
(
[0] => /home/ubuntu/projects/xyz.com/code/ciapp/views/pages/file1.php
[1] => /home/ubuntu/projects/xyz.com/code/ciapp/views/pages/file2.php
[2] => /home/ubuntu/projects/xyz.com/code/ciapp/views/pages/file3.php
[3] => /home/ubuntu/projects/xyz.com/code/ciapp/views/pages/folder1/file4.php
[4] => /home/ubuntu/projects/xyz.com/code/ciapp/views/pages/folder1/file5.php
[5] => /home/ubuntu/projects/xyz.com/code/ciapp/views/pages/folder1/folder2/file6.php
[6] => /home/ubuntu/projects/xyz.com/code/ciapp/views/pages/folder3/file7.php
[7] => /home/ubuntu/projects/xyz.com/code/ciapp/views/pages/folder3/file8.php
)
[directories] => Array
(
[0] => /home/ubuntu/projects/xyz.com/code/ciapp/views/pages/folder1
[1] => /home/ubuntu/projects/xyz.com/code/ciapp/views/pages/folder1/folder2
[2] => /home/ubuntu/projects/xyz.com/code/ciapp/views/pages/folder3
)
)
3)我得到的(只有1级)-
Array
(
[files] => Array
(
[0] => /home/ubuntu/projects/xyz.com/code/ciapp/views/pages/file1.php
[1] => /home/ubuntu/projects/xyz.com/code/ciapp/views/pages/file2.php
[2] => /home/ubuntu/projects/xyz.com/code/ciapp/views/pages/file3.php
)
[directories] => Array
(
[0] => /home/ubuntu/projects/xyz.com/code/ciapp/views/pages/folder1
[1] => /home/ubuntu/projects/xyz.com/code/ciapp/views/pages/folder3
)
)
4)我的功能 -
function get_files_directories($directory, $a = array())
{
$dirs = scandir($directory, 1);
$arr = $a;
foreach($dirs as $dir)
{
if($dir != "." && $dir != '..')
{
$new_dir = $directory.'/'.$dir;
if(is_dir($new_dir))
{
$arr['directories'][] = $new_dir;
get_files_directories($new_dir, $arr);
}
else
{
$arr['files'][] = $new_dir;
}
}
}
return $arr;
}
$my_dir = "/home/ubuntu/projects/xyz.com/code/ciapp/views/pages";
$files_dirs = get_files_directories($my_dir);
echo '<pre>'; print_r($files_dirs);
我在这里想念什么?帮助将不胜感激。谢谢 :)