ouzo icon indicating copy to clipboard operation
ouzo copied to clipboard

`FluentArray.skip()` and `limit()` leak `array_slice()` implementation detail

Open danon opened this issue 3 years ago • 0 comments

If you run this

$array = [
    'Key' => 'One',
    10    => 'Two',
    20    => 'Three'
];
//when
$result = FluentArray::from($array)->limit(2)->toArray();

The resulting array is ['Key' => 'One', 0 => 'Two'], which doesn't make any sense. Same for skip(). (array_slice() reindexes integer keys, but keeps string keys -.-)

What should be done now is:

  • limit() and skip() should preserve keys (add true flag to array_slice()) - this probably makes more sense
  • limit() and skip() should reindex the array (use array_values())

danon avatar Apr 27 '22 10:04 danon