1
juneszh 2017-09-22 08:54:26 +08:00
这代码看得累
|
2
yejinmo 2017-09-22 09:15:21 +08:00
public function getFolder($dir, $num)
{ $targetDir = rtrim($dir, '/'); if (!is_dir($targetDir)) return false; $result = false; $folders = scandir($targetDir); foreach ( $folders as $folder) { if($folder == '.' || $folder == '..' || $folder == '__MACOSX' || $folder == '.DS_Store') { continue; } $subDir = $targetDir . DIRECTORY_SEPARATOR . $folder; if (!is_dir($subDir)) continue; if ($folder == $num) { $result = $targetDir . DIRECTORY_SEPARATOR . $folder; return $result; } else { return $this->getFolder($subDir, $num); } } } |
4
sortbylist 2017-09-22 09:29:12 +08:00
递归要有收敛,if ($folder == $num) 这个条件能成立么?不能成立就无限递归了。
|
5
CEBBCAT 2017-09-22 09:48:18 +08:00 via Android
说句无关的:V2EX 贴代码可以用 gist
|