3 ms·
PHP arrays are associative arrays, it has to update the keys for every remaining value after the first element is deleted.
by Izkata 4y ago
PHP arrays are associative arrays, it has to update the keys for every remaining value after the first element is deleted.
- actually_a_dog 4y agoThat seems like some kind of local fitness minimum in the space of design choices. Even though there certainly are worse choices one could make, I couldn't imagine anything much worse than that would even stand up to any sort of use.
- TazeTSchnitzel 4y agoPHP does at least have an optimised internal representation for arrays with sequential integer keys, where it can avoid having a hash table and just do linear indexing: https://www.npopov.com/2014/12/22/PHPs-new-hashtable-implementation.html#packed-hashtables https://www.npopov.com/2014/12/22/PHPs-new-hashtable-impleme... But a tradeoff in that design is it still has to keep track of keys and update them if you remove stuff from the start of the array. Adding and removing elements at the end is very fast, though.