2010-12-15 49 views
1

我有一個圖像名稱的數組,從圖像名稱數組中刪除的數組值,以及一個日期數組。PHP:array help

$images = scandir($dir); 
$filestomove = array('home-accessories----candles.jpg'); 
$displayDates = array('25/12/2010', '26/12/2010'); 

基本上我想遍歷顯示日期陣列如果沒有值的數組==今天的日期,然後我想做的事情上$圖像和$ filetomove的和array_diff。

這是我遇到麻煩的循環。

這裏是我的代碼:

$images = scandir($dir); 
$images2 = array(); 
//array of filenames to move from images array 
$filestomove = array('home-accessories----candles.jpg'); 

//creates date in the format of 15/12/2010 
$format = 'd/m/Y'; 
// date of current day 
$today = date($format); 
//date display the ad 
$displayDates = array('25/12/2010', '26/12/2010'); 

foreach ($displayDates as $key => $value){ 
    if($today != $value){ 
     //remove the filenames from the array and create new array 
     $images2 = array_diff($images, $filestomove); 
     //overwrite the old array with the new one 
     $images = $images2; 
     break; 
    } 
} 

這裏的問題是,如果第一個值是不是今天的日期,將刪除陣列項目,然後打破循環,即使第二陣列項目可能是今天日期。

我需要幫助做這個循環。我不確定如何檢查$ displayDates數組,並且只在今天的日期不在數組中時移除數組項。

任何幫助將不勝感激!

問候,

比利

回答