I have various items in my $positions array and do the following:
foreach ($positions as &$position) {
if ($position['date'] == $order['date']) {
unset($position);
}
}
var_dump($positions);
The var_dump still displays the $position which should be excluded.
When I do
foreach ($positions as $key => &$position) {
if ($position['date'] == $order['date']) {
unset($positions[$key]);
}
}
It does remove far more items than expected.
Anybody knows what happens here in both cases and how why does unset($position) not work? I reference the item in the foreach loop with '&'.
Thanks!