I know the title looks weird but this is what just happened to me.
I have created a funtion that takes DateTime and integer and return array of dates, and this is my code:
public static function generateAfterDate(\DateTime $from, $number){
$days = array();
array_push($days, $from);
for($i = 1; $i <= $number; $i++){
$from = $from->modify('+1 day');
$days[] = $from;
var_dump($days[$i]->format('d/m/Y'));//---The first var_dump
}
foreach ($days as $day){
var_dump($day->format('d/m/Y'));//--The second var_dump
}
die;
return $days;
}
generateAfterDate(new \DateTime(), 7);
As you can see I'm using the same array to var_dump data and I get two different results:
The first one gave me this:
string(10) "22/10/2017" string(10) "23/10/2017" string(10) "24/10/2017" string(10) "25/10/2017" string(10) "26/10/2017" string(10) "27/10/2017" string(10) "28/10/2017"
And the second one gave me this result:
string(10) "28/10/2017" string(10) "28/10/2017" string(10) "28/10/2017" string(10) "28/10/2017" string(10) "28/10/2017" string(10) "28/10/2017" string(10) "28/10/2017" string(10) "28/10/2017"
Can someone please explain this ?