我可以用一些帮助.我必须从一个目录获取文件列表,并将它们作为数组返回,但键需要与值相同,因此输出将如下所示:
array(
'file1.png' => 'file1.png',
'file2.png' => 'file2.png',
'file3.png' => 'file3.png'
)
Run Code Online (Sandbox Code Playgroud)
我找到了这段代码:
function images($directory) {
// create an array to hold directory list
$results = array();
// create a handler for the directory
$handler = opendir($directory);
// open directory and walk through the filenames
while ($file = readdir($handler)) {
// if file isn't this directory or its parent, add it to the results
if ($file != "." && $file != "..")
{
$results[] = $file;
}
}
// tidy …Run Code Online (Sandbox Code Playgroud)