I always did something like
e.g. from my last project in Laravel
foreach( $sections as $section )
{
$section->date = Carbon::parse($section->date)->diffForHumans();
}
And it worked well. Never problem with that, array was modified as I wanted
But now I did this
$events = $this->events;
foreach($events as $event)
{
$date = new \DateTime($event['date']);
$event['date'] = (int)$date->format('d');
echo $event['date'];
var_dump($event);
}
var_dump($events);
$this->events = $events;
And it doesn't work as I want, different values inside loop and outside loop.
I was looking what is bad and I found what it is about, to give &
or do foreach $key => $value...
But it would be okay.
But it isn't.
Because I know. I remember. I did many times just something like
foreach($a as $b)
{
$b = .......
}
And it worked. But now it isn't.
So I don't understand. But I have to and want to.
I was searching for answer, but can find it.
Why for one time it works for me like that, and other time doesn't work and I need apersand or key => value playing?
Please give me understanding <3
Why one time it is working but another not.