You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
1.8 KiB

<?php
/**
* Created by PhpStorm.
* User: Wind
* Date: 2017/10/25
* Time: 13:46
*/
$test_data = [
['id' => 0, 'name' => 'A'],
['id' => 1, 'name' => 'a', 'pid' => 0],
['id' => 2, 'name' => 'b', 'pid' => 1],
['id' => 3, 'name' => 'c', 'pid' => 1],
['id' => 4, 'name' => 'd', 'pid' => 0],
['id' => 5, 'name' => 'e', 'pid' => 4],
];
function m_tree($arr, $pid = 0)
{
$tree = [];
foreach ($arr as $tmp) {
if (!isset($tmp['pid'])) {
$tree[] = $tmp;
} elseif($tmp['pid'] == $pid){
$tree[$pid][$tmp['id']] = $tmp;
} /*else {
if ($tmp['pid'] > $pid)
$tree[$pid][] = m_tree($arr, $tmp['pid']);
}*/
}
return $tree;
}
echo '<pre>';
print_r(m_tree($test_data));
echo '</pre>';
die;
function tree($directory)
{
$mydir = dir($directory);
echo "<ul>\n";
while ($file = $mydir->read()) {
if ($directory == '/') {
$child = $directory . $file;
} else {
$child = "$directory/$file";
}
if ((is_dir($child)) AND ($file != ".") AND ($file != "..") AND ($file != '$RECYCLE.BIN') AND ($file != 'System Volume Information')) {
var_dump("directory: " . $child);
echo "<li><font color=\"#ff00cc\"><b>$file</b></font></li>\n";
tree($child);
} else
echo "<li>$file</li>\n";
}
echo "</ul>\n";
$mydir->close();
}
function getChmod($filepath)
{
return substr(base_convert(@fileperms($filepath), 10, 8), -4);
}
$dirs = tree('/');
var_dump($dirs);
var_dump(is_writable('/test'));
$perms = getChmod('/test/');
var_dump(fileperms('/test'));
var_dump(scandir('/'));
var_dump($_SERVER['DOCUMENT_ROOT']);
chdir('d:/www');
var_dump(scandir('/'));
echo getcwd();