我有任務,我必須找到最近添加的文件夾(這是由日期命名)。問題是,當我與所有文件夾與日期獲取目錄我的數組包含完整路徑的文件夾不僅日期文件夾。讓MI給你和示例代碼的我和樣品從放...獲取最近的日期的文件夾
這是我的代碼
$dirs = array_filter(glob(__DIR__ . '/../../../var/Html/*'), 'is_dir');
var_dump($dirs);
$mostRecent= 0;
foreach($dirs as $date){
$curDate = strtotime($date);
if ($curDate > $mostRecent) {
$mostRecent = $curDate;
}
}
var_dump($mostRecent);
die();
這是輸出我得到
D:\wamp64\www\mypage\public_html\rest>php index.php cli/pars parseFiles
array(2) {
[0]=>
string(111) "D:\wamp64\www\mypage\public_html\rest\application\controllers\cli/../../../var/Html/2017-07-15"
[1]=>
string(111) "D:\wamp64\www\mypage\public_html\rest\application\controllers\cli/../../../var/Html/2017-07-16"
}
int(0)
所以,我認爲,問題是因爲var $ dirs包含我的dirs的完整路徑,而不是僅包含日期文件夾名稱。我如何克服我的問題?謝謝
你可以得到你要尋找一個使用'基本名的目錄()'。 – jeroen
如果將這些結果放入數組中,則可以輕鬆地對數組進行排序。 – jeroen