I've been wondering for some time why PHP does not have the ability to
efficiently insert string keys before/after an existing string key.
Let's say I have an array of 10,000 string key/value pairs and I want to
insert five new string key/value pairs at specific positions in the
existing array. Unless I've missed something, despite looking at each
of the array_...() functions, this is not possible in userland without
copying the entire array to insert the new elements (or some real
hackery such as append with some tracking info and use a function like
uksort() to somehow only move the newly added items). There are several
userland functions in the PHP documentation comments and also on
StackOverflow that end up recreating the array each time they are
called. Several examples:
https://stackoverflow.com/a/7257599/917198
http://us1.php.net/manual/en/function.array-splice.php
As the author of the OrderedHash implementation here:
https://github.com/cubiclesoft/cross-platform-cpp
I provide an ordered hash data structure that is similar-ish to the PHP
array implementation, but it also has support for inserting a node
anywhere in the OrderedHash by making a few pointer adjustments.
Shifting a few pointers around is usually magnitudes faster than
performing memory allocations and copying data.
--
Thomas Hruska
CubicleSoft President
I've got great, time saving software that you will find useful.
http://cubiclesoft.com/
And once you find my software useful:
http://cubiclesoft.com/donate/
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php