I have a sort array of dates. I want to go from a specific begin date to a specific end date, and increment a variable each time I find the given date in the array. Í tried with the following code snippet:
$result = array();
$iterator = 0;
for ($minDateTime = new DateTime($minDate); $minDateTime <= new DateTime($maxDate); $minDateTime->add(new DateInterval('P01D'))) {
if ($minDateTime = $myDateArray[$iterator]) {
$iterator++;
}
array_push($result, "$minDateTime=>$iterator");
}
If I want to run this code I got the following error:
Fatal error: Call to a member function add() on a non-object in /home/pivoecom/public_html/teszt/query_test.php on line 34
Where line 34 is the opening of the for cycle. I read the reference of DateTime and I'm sure that there is an add method for it. I tried to add day with this line outside the for cycle and it worked... What do I do wrong?