Description
When using the Collection::filter()
method, the resulting collection retains the indices of the filtered out items, which may not yield the expected behavior when using ArrayAccess
functionality.
$c = new Collection([0, 1, 2]);
$filtered = $c->filter(fn ($i) => $i % 2);
The expected behavior would be that $filtered[0] == 0
and $filtered[1] == 2
, but only the former is true, since it retains the indices of the original array, i.e. $filtered[2] == 2
is true, even though count($filtered) == 2
.