On Tue, May 2, 2017 at 7:55 PM, Rowan Collins <rowan.coll...@gmail.com>
wrote:

> +1, I've been thinking of making a similar suggestion. We can bikeshed the
> name (it should certainly start with "array_"), but I think there's a very
> good case for having an optimised implementation built in, given the
> opportunities for short-cutting based on representation details.
>

Something like array_is_vectorlike(), array_is_vector() or
array_is_sequential() sound good to me. You could also do the opposite,
array_is_assoc().

As an example use case, serialization formats often dynamically switch
> between an "array"/"vector"/"list", and a "hash"/"dictionary"/"table". I
> came upon this example recently: https://github.com/php-amqplib
> /php-amqplib/blob/master/PhpAmqpLib/Wire/AMQPAbstractCollection.php#L218


Another reason this function would be of utility is that it would
discourage even more inefficient implementations that allocate new arrays,
like the one in that code ("array_keys($val) === range(0, count($val) -
1)"), and nearly every single answer to this StackOverflow question (except
mine):
https://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential/

Reply via email to