Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75734 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 14575 invoked from network); 21 Jul 2014 03:20:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Jul 2014 03:20:26 -0000 Authentication-Results: pb1.pair.com smtp.mail=tjerk.meesters@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=tjerk.meesters@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.174 as permitted sender) X-PHP-List-Original-Sender: tjerk.meesters@gmail.com X-Host-Fingerprint: 209.85.220.174 mail-vc0-f174.google.com Received: from [209.85.220.174] ([209.85.220.174:42236] helo=mail-vc0-f174.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FA/F9-48607-8F68CC35 for ; Sun, 20 Jul 2014 23:20:25 -0400 Received: by mail-vc0-f174.google.com with SMTP id la4so11163259vcb.33 for ; Sun, 20 Jul 2014 20:20:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=Cq8xo55PZpB3md8F5G2B3gXJmigfNp/PwvfO4C0/t8E=; b=bLSgGdUbI2yPYgND9o8QGlRhCvLM2pNhq3W15mhRMi6wHM07QSwvyYJmKNIAhjWqnA GVe7r03phg9mYkDWD2gk0ad74t5M4617149XA8ak8lm2pp55uoORxaYqIxYQxPIeKRsx tv2nAEhqr6XPHJx8D2FXwRQbir9N/5QQDsAIwBY/lFTgcM1sGS33IEnd72IJAxAj4UZR jsU8QQimjWcDSyAuaQ8CLE2ANNy/oxjnjT2C8SwKAKGYkCatjE0Z/mHeU064/ZKr0rKA kLwjfrh1SPJSzmX8r1+yrxjjJXQxmCgPXflLnndhQDNnH80o1ank+KzBuxlQtC5BK276 SdWw== MIME-Version: 1.0 X-Received: by 10.52.31.104 with SMTP id z8mr6500207vdh.23.1405912821893; Sun, 20 Jul 2014 20:20:21 -0700 (PDT) Received: by 10.58.89.170 with HTTP; Sun, 20 Jul 2014 20:20:21 -0700 (PDT) In-Reply-To: References: Date: Mon, 21 Jul 2014 11:20:21 +0800 Message-ID: To: Aaron Lewis Cc: PHP Internals Content-Type: multipart/alternative; boundary=bcaec51d257e5593ae04feab9670 Subject: Re: [PHP-DEV] What's wrong with these hashtable iteration code? From: tjerk.meesters@gmail.com (Tjerk Meesters) --bcaec51d257e5593ae04feab9670 Content-Type: text/plain; charset=UTF-8 On Mon, Jul 21, 2014 at 11:12 AM, Aaron Lewis wrote: > Hi, > > I'm trying to iterate through a hash table, > > But the zend_hash_get_current_key() doesn't seem to move forward: > I'm getting duplicate output at the 'fprintf' part. > > for(zend_hash_internal_pointer_reset_ex(ht, &pos); > zend_hash_has_more_elements_ex(ht, &pos) == SUCCESS; > zend_hash_move_forward_ex(ht, &pos)) > { > if (zend_hash_get_current_key (ht, &string_key, &num_key, 0) > != HASH_KEY_IS_STRING) > continue; > > fprintf (stderr, "string key: %s\n", string_key); > } > The _ex() hash iteration functions allow for iterating a hash without modifying its internal pointer, but zend_hash_get_current_key() uses only the internal pointer. The function you need to use is: zend_hash_get_current_key_ex() and pass &pos to it. > > Any ideas? > > > -- > Best Regards, > Aaron Lewis - PGP: 0x13714D33 - http://pgp.mit.edu/ > Finger Print: 9F67 391B B770 8FF6 99DC D92D 87F6 2602 1371 4D33 > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > -- -- Tjerk --bcaec51d257e5593ae04feab9670--