2
我想從特定路徑文件夾ID和子文件夾parent_id中獲取文件夾和子文件夾。 在這裏我的功能獲取文件夾和子文件夾,但沒有ID和父母的ID。如何檢索包含文件夾ID的數組中的目錄結構
我想用id和父id的數組。
function getDirectory($path = '.', $level = 1) {
$result = array();
$ignore = array('nbproject', 'src', '.', '..');
$dh = @opendir($path);
$i = 0;
while ($file = readdir($dh)) {
if (!in_array($file, $ignore)) {
if (is_dir($path . '/' . $file)) {
$level++;
$singleResult = array('title' => $file, 'isFolder' => true, 'children' => getDirectory($path . '/' . $file, $level), 'key' => 'node' . $level);
$result[] = $singleResult;
}
}
$i++;
}
closedir($dh);
return $result;
}
$dir = "../UserUpload/Documents/source";
$kevin = getDirectory($dir);
這個功能給我數組這樣wiithout ID和父ID
array (size=3)
0 =>
array (size=4)
'title' => string 'mst146' (length=6)
'isFolder' => boolean true
'children' =>
array (size=3)
0 =>
array (size=4)
...
1 =>
array (size=4)
...
2 =>
array (size=4)
...
'key' => string 'node2' (length=5)
1 =>
array (size=4)
'title' => string 't124' (length=4)
'isFolder' => boolean true
'children' =>
array (size=0)
empty
'key' => string 'node3' (length=5)
2 =>
array (size=4)
'title' => string 'test' (length=4)
'isFolder' => boolean true
'children' =>
array (size=0)
empty
'key' => string 'node4' (length=5)
你是什麼意思的ID?文件夾通常沒有ID。 – maxhb
但我想給id文件夾@maxhb –
ID應該從哪裏來?如果您只需要與文件夾相關的獨特內容,請使用它的路徑。 – maxhb