I have an array of image names, an array of array values to remove from the image name array, and an array of dates.
$images = scandir($dir);
$filestomove = array('home-accessories----candles.jpg');
$displayDates = array('25/12/2010', '26/12/2010');
Basically I want to loop through the display dates array and if none of the values in the array == todays date then I want to do an array_diff on $images and $filetomove.
It's the looping that I'm having trouble with.
Here is my code:
$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;
}
}
The problem here is that if the first value is not todays date it will remove the array item and then break the loop, even though the second array item might be todays date.
I need help doing this looping. I'm unsure how to check through the $displayDates array and only remove the array item if todays date is not in the array.
Since your condition is
if none of the values in the array == todays
You should check out http://php.net/manual/en/function.in-array.php
if(!in_array($today, $displayDates) {
// do work
}