如何在此函数中获取路径?这个函数只给我名字,但我想获取路径该怎么做?
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' => '/' . $file);
$result[] = $singleResult;
}
}
$i++;
}
closedir($dh);
return $result;
}
$dir = "../UserUpload/Documents/source";
$kevin = getDirectory($dir);
这个函数给了我这样的数组。我也想在这个数组中获取路径该怎么做?
array (size=3)
0 =>
array (size=4)
'title' => string 'mst146' (length=6)
'isFolder' => boolean true
'children' =>
'key' => string '/mst146' (length=7)
1 =>
array (size=4)
'title' => string 't124' (length=4)
'isFolder' => boolean true
'children' =>
'key' => string '/t124' (length=5)
2 =>
array (size=4)
'title' => string 'test' (length=4)
'isFolder' => boolean true
'children' =>
'key' => string '/test' (length=5)
在你的$singleResult
行中尝试:
'key' => realpath($path . '/' . $file)