【发布时间】:2018-09-14 20:45:12
【问题描述】:
我的目录结构如下图。
C:\xampp\htdocs\rosoka\file
----- 2018-03-02
-------------test1.json
-------------test2.json
----- 2018-03-03
-------------test3.json
-------------test4.json
我希望我的所有文件夹都成为函数外最后一个跟踪上这样关联的数组的键
Array ( [C:/xampp/htdocs/rosoka/file] => Array ( ))
Array ( [C:/xampp/htdocs/rosoka/file/2018-03-02] => Array ())
Array ( [C:/xampp/htdocs/rosoka/file/2018-03-03] => Array ())
这是我的源代码请帮帮我。
<?php
$no_entity = array();
listFolderFiles("C:/xampp/htdocs/rosoka/file", $no_entity);
function listFolderFiles($dir, $no_entity){
echo "<br>";
if (array_key_exists($dir, $no_entity)) {
echo "why no result here??? T_T";
} else {
$no_entity[$dir] = array();
print_r($no_entity);
}
$real_path = "C:/xampp/htdocs/rosoka/file";
$real_path = str_replace($real_path,"",$dir);
set_time_limit (3000000);
ini_set('memory_limit', '-1');
$ffs = scandir($dir);
unset($ffs[array_search('.', $ffs, true)]);
unset($ffs[array_search('..', $ffs, true)]);
$ffs = array_values($ffs);
if (count($ffs) < 1)
return;
foreach($ffs as $ff){
if(is_dir($dir.'/'.$ff)) {
listFolderFiles($dir.'/'.$ff, $no_entity);
} else {
}
}
}
// "WHERE MY ARRAY T_T";
var_dump($no_entity);
?>
(用于测试 ekstract 到 htdocs) https://drive.google.com/file/d/1dtXbQFrWoD0dQFOb-2YRqcH4eKPUTzZ9/view?usp=sharing
【问题讨论】:
-
样本数据是什么(即您测试代码的实际目录列表),预期结果是什么,实际结果是什么?
-
drive.google.com/file/d/1dtXbQFrWoD0dQFOb-2YRqcH4eKPUTzZ9/… thx 先生的回答,我对 var_dump 的期望
-
谷歌驱动器链接预览不正确。
-
我的朋友可以下载先生
标签: php xampp directory php-node