Trying to build array from date range
Posted: Fri Aug 04, 2006 12:10 am
Hi all, My brain must be dead today, because this relatively simple solution I am trying to come up with, I just can't get it working.
I have a class like this
Now I have an array of class item, this is the array
alright, now what I want to do is this ...
I then want a loop that loops threw the $itemArray and builds a new array that is active between that date range.
So with that start and end date, item1, item2, and item3 should all be in the array, but item4 shouldnt since it doesnt fall in the range.
Now I know this should be relatively simple, but for some reason my brain isn't working today.
Thanks in advance
I have a class like this
Code: Select all
class item
{
private $itemName;
private $activeFrom;
private $activeTo;
function __construct($itemName, $activeFrom, $activeTo)
{
$this->itemName = $itemName;
$this->activeFrom = $activeFrom;
$this->activeTo = $activeTo;
}
}Now I have an array of class item, this is the array
Code: Select all
$itemArray = array();
$item = new item("item1", "2006-01-01", "2006-01-10");
$itemArray[] = $item;
$item = new item("item2", "2006-01-10", "2006-01-15");
$itemArray[] = $item;
$item = new item("item3", "2006-01-15", "2006-01-20");
$itemArray[] = $item;
$item = new item ("item4", "2006-01-20", "2006-01-28");
$itemArray[] = $item;Code: Select all
$startDate = "2006-01-05";
$endDate = "2006-01-18";So with that start and end date, item1, item2, and item3 should all be in the array, but item4 shouldnt since it doesnt fall in the range.
Now I know this should be relatively simple, but for some reason my brain isn't working today.
Thanks in advance