So, long story short, I have an array of date objects ($occupied).
I want to compare these dates to a $now=dateTime() so that any $occupied[$i] that happens before $now will get removed. I have tried some solution with unset, another one with (a brand new) array_push(). Neither of it has worked, so i guess i am missing some logic apart from the obvious.. Any approach is welcome :) Here is interesting part of the code:
$occupied=["2016-02-19", "2016-02-20", "2016-02-21", "2016-02-18", "2016-02-19", "2016-02-20", "2016-02-21", "2016-03-30", "2016-03-25", "2016-03-26"].
$now = new DateTime();
my ideas included:
$now= new dateTime();
for($i=0;$i<count($occupied);$i++){
$occupied[$i]=new dateTime($occupied[$i]);
$diff[$i] = $now->diff($occupied[$i]);
echo $diff[$i]->format('%r%a');
if(get_object_vars($diff[$i])["invert"]==1){
unset($occupied[$i]);
}
}
and variations over the theme.. Apologize if it is trivial, my background is very basic... I have tried to avoid posting by reading PHP manual and some answers here featuring "remove values from array//remove elements by key" but I could not figure it out..
Thanks in advance!