I recently found out that array_values() works differently for sequential and associative arrays.
I noticed that for some arrays array_values() resets internal array pointer, and for some it doesn't. Turns out, that array_values() only creates a new array if would be different. Sequential arrays would always be the same, so array_values() doesn't copy it, so the internal pointer is preserved.
I've written a failing unit test, you can see it's behaviour on the screen:
PS: What's funny, is that array_keys() and other methods don't have this behaviour, it's only array_values().
PS2: Perhaps apart from FluentArrays.values() also Arrays.values() could be added, which always returns a new array.
I recently found out that
array_values()
works differently for sequential and associative arrays.I noticed that for some arrays
array_values()
resets internal array pointer, and for some it doesn't. Turns out, thatarray_values()
only creates a new array if would be different. Sequential arrays would always be the same, soarray_values()
doesn't copy it, so the internal pointer is preserved.I've written a failing unit test, you can see it's behaviour on the screen:
PS: What's funny, is that
array_keys()
and other methods don't have this behaviour, it's onlyarray_values()
. PS2: Perhaps apart fromFluentArrays.values()
alsoArrays.values()
could be added, which always returns a new array.