Question about hashtables implementation

From: Date: Sun, 02 Sep 2012 17:16:06 +0000
Subject: Question about hashtables implementation
Groups: php.internals 
Request: Send a blank email to internals+get-62676@lists.php.net to get a copy of this message
Hi all, I have a question about the internal implementation of PHP's hashtables. I did some researches, but I didn't find the answer. Here is an example of what I would like to understand. Start by creating an array: $a = array(); Fill it, using implicit and explicit keys: $a[] = 'cc'; $a[1] = 'dd'; If we look at what's inside, we get: Array ( [0] => cc [1] => dd ) OK, everything is obvious. Now, I add a value at the beginning of the array: array_unshift($a, 'ee'); Do a print_r() again: Array ( [0] => ee [1] => cc [2] => dd ) As you can see, the keys for 'cc' and 'dd' have been recalculated. It works as espected. My question is how does it work? Are all numeric keys computed when the array_shift() is done? Or is the iterator calculating them on-the-fly? Thanks. Amaury

« previous php.internals (#62676) next »