Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75735 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 16026 invoked from network); 21 Jul 2014 03:23:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Jul 2014 03:23:51 -0000 Authentication-Results: pb1.pair.com header.from=the.warl0ck.1989@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=the.warl0ck.1989@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.219.53 as permitted sender) X-PHP-List-Original-Sender: the.warl0ck.1989@gmail.com X-Host-Fingerprint: 209.85.219.53 mail-oa0-f53.google.com Received: from [209.85.219.53] ([209.85.219.53:54796] helo=mail-oa0-f53.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 11/5A-48607-6C78CC35 for ; Sun, 20 Jul 2014 23:23:51 -0400 Received: by mail-oa0-f53.google.com with SMTP id j17so6373933oag.26 for ; Sun, 20 Jul 2014 20:23:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:cc:content-type; bh=+ilL61Fc64r1xylMbe3UlD2gUSuyzpnpmWuXhHC9s4Y=; b=vN+arsvWd3yU4mWQpGbtb0ZgpxP2TV0OegPHT438sfn2zCAAbuJTcHL23nq4zGaqBV 1GXJUiaSNcBm8Ew0f+aNVFHQG62FCZ5sVqO/2mBYx2uRBBmB6s3gB7Td/mELMnpkZWWG 02uPAPiTFbElJP2bFkVpfyxq5mQefdJs5+wjz8pzyRytpfBH10plOrK8jCo5j4aIF0tm 4SQLHVTj9JclAT9WE/eNYNt3ZYMTOLIR7oaof6Q7gVyJlVPBOWJeEnRJf2NIM2dOer04 E5n0xFMLWDb2EdikfOcHRt6lOMNNJ2szl3zxNnXjDoXRS63jZWkegU3MghO9+LQHU7a4 bd8A== MIME-Version: 1.0 X-Received: by 10.182.112.134 with SMTP id iq6mr32022511obb.34.1405913028459; Sun, 20 Jul 2014 20:23:48 -0700 (PDT) Received: by 10.76.23.102 with HTTP; Sun, 20 Jul 2014 20:23:48 -0700 (PDT) Date: Mon, 21 Jul 2014 11:23:48 +0800 Message-ID: To: Tjerk Meesters Cc: PHP Internals Content-Type: text/plain; charset=UTF-8 Subject: [RESOLVED] Re: [PHP-DEV] What's wrong with these hashtable iteration code? From: the.warl0ck.1989@gmail.com (Aaron Lewis) Thanks! It worked On Mon, Jul 21, 2014 at 11:20 AM, Tjerk Meesters wrote: > > > > 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 -- Best Regards, Aaron Lewis - PGP: 0x13714D33 - http://pgp.mit.edu/ Finger Print: 9F67 391B B770 8FF6 99DC D92D 87F6 2602 1371 4D33