Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62676 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 1796 invoked from network); 2 Sep 2012 17:16:31 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Sep 2012 17:16:31 -0000 Authentication-Results: pb1.pair.com smtp.mail=amaury.bouchard@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=amaury.bouchard@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.170 as permitted sender) X-PHP-List-Original-Sender: amaury.bouchard@gmail.com X-Host-Fingerprint: 209.85.214.170 mail-ob0-f170.google.com Received: from [209.85.214.170] ([209.85.214.170:32882] helo=mail-ob0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A8/51-17065-E6493405 for ; Sun, 02 Sep 2012 13:16:30 -0400 Received: by obbwc18 with SMTP id wc18so8802753obb.29 for ; Sun, 02 Sep 2012 10:16:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:from:date:x-google-sender-auth:message-id :subject:to:content-type; bh=psef7vdyyZ6158FLmd83MF5bggVJPIMbCdm2GumSR7Y=; b=dvw5bP31ErzVM7OEfiDH/DXKvy9nvE+ISYvWBwsJa7vKrd3JKKaTZkCkPRF2vGfNbO fzbqvH6hPalX4WZuYvBYLmcQAJdXCJM/s4CBFQHj325Y4hakKT3OfzMldAOl/NhaS7E0 PuTMQ2SK1jGXm69037Vv8pdGwjrZK1h53ZqHTEBCdKgWdOmLrBe0RoDSL3QNhtJbDPSx cXK5rPoiTo744tis65Vq0rEZLfUTMTuGR58O9ha8lj00b06w+Ex82u2UF/KufB5yN4y/ 8usrddrBwAcqTBjF0nkixgk7I+XOIyTiH3eeVWq0lqNan1VXr2xUMetseYEfrmL340UG D75A== Received: by 10.182.202.6 with SMTP id ke6mr12353554obc.83.1346606187825; Sun, 02 Sep 2012 10:16:27 -0700 (PDT) MIME-Version: 1.0 Sender: amaury.bouchard@gmail.com Received: by 10.182.193.68 with HTTP; Sun, 2 Sep 2012 10:16:06 -0700 (PDT) Date: Sun, 2 Sep 2012 19:16:06 +0200 X-Google-Sender-Auth: nLvcrgxnJYoed2T-WJEYum3fmZI Message-ID: To: PHP Internals Content-Type: multipart/alternative; boundary=e89a8f6434b67a48d804c8bb2f65 Subject: Question about hashtables implementation From: amaury@amaury.net (Amaury Bouchard) --e89a8f6434b67a48d804c8bb2f65 Content-Type: text/plain; charset=ISO-8859-1 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 --e89a8f6434b67a48d804c8bb2f65--