-4

如何将以下结果转换为数组?我想创建一个数组,这样我就可以分配给变量并使用它

if($handle = opendir($path)){
    while(false != ($filename = readdir($handle))) {
        if($filename != "." && $filename != ".."){
            $name = preg_replace("/\\.[^.\\s]{3,4}$/", "", $filename);
            $name = str_replace('_', ' ', $name);
            $name = ucwords($name);
                echo $name;
        }           
    }
    closedir($handle);
}
4

1 回答 1

2

只需将名称添加到数组中......

$files = array();
if($handle = opendir($path)){
    while(false != ($filename = readdir($handle))) {
        if($filename != "." && $filename != ".."){
            $name = preg_replace("/\\.[^.\\s]{3,4}$/", "", $filename);
            $name = str_replace('_', ' ', $name);
            $name = ucwords($name);
            $files[] = $name;
        }           
    }
    closedir($handle);
}
于 2013-06-29T18:40:57.830 回答