François Laupretre wrote on 08/02/2016 15:44:
For a better consistency, may I suggest a function that would allow to know whether array keys are all numeric, all strings, or mixed. Something like array_keys_type() returning one of 3 predefined constants : ARRAY_KEYS_NUMERIC, ARRAY_KEYS_STRING, ARRAY_KEYS_MIXED.

The problem with this is that it's significantly harder to optimise than cases where you are falsifying a single hypothesis:

- if the question is "are all keys integers?", you can return false as soon as you find a string key - if the question is "are all keys strings?", you can return false as soon as you find an integer key - if the question is "does the array contain both types of key?", you can return false as soon as you have found one of each type of key

Combining the functions allows the 3rd optimisation only, which is probably the least common use case. In the OP's use case, given a large array consisting only of string keys, the function would have to examine every key to decide whether to return ARRAY_KEYS_STRING or ARRAY_KEYS_MIXED, although the user doesn't care about that distinction.

Regards,
--
Rowan Collins
[IMSoP]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to