I declared a variable of collect() data type. I want to iterate through it, and to update specific column on each row.
The example code:
$a = collect([
['one' => 1, 'two' => 2],
['one' => 3, 'two' => 4],
['one' => 5, 'two' => 6]
]);
foreach ($a as $b) {
$b['one'] = 0;
}
dd($a);
I don't understand, why the result is this:
Collection {#510 ▼
#items: array:3 [▼
0 => array:2 [▼
"one" => 1
"two" => 2
]
1 => array:2 [▼
"one" => 3
"two" => 4
]
2 => array:2 [▼
"one" => 5
"two" => 6
]
]
}
I expect "one" => 0 as a result for each row.