Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51155 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 17019 invoked from network); 31 Dec 2010 14:13:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 31 Dec 2010 14:13:10 -0000 Authentication-Results: pb1.pair.com smtp.mail=rquadling@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rquadling@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.42 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: rquadling@gmail.com X-Host-Fingerprint: 209.85.216.42 mail-qw0-f42.google.com Received: from [209.85.216.42] ([209.85.216.42:48827] helo=mail-qw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 25/C2-01063-4F4ED1D4 for ; Fri, 31 Dec 2010 09:13:08 -0500 Received: by qwj8 with SMTP id 8so12060524qwj.29 for ; Fri, 31 Dec 2010 06:13:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:reply-to :in-reply-to:references:from:date:message-id:subject:to:cc :content-type:content-transfer-encoding; bh=B07By+R7D9fCcejONBDwOwchc4pM9xApt+lF2WtjX/g=; b=X1MykL0aLiMrtU6OqPpWLzwaWQVedwb41K3l9OvedyeFFw6ycfFto91508yHo0I5yK OjQpIDYDrA/YcFwwk5qLC2VThga9PUnpQMUeGbolCwzjGcy9Yd4JIHMU+4TA0IVtNXlf MIlhBKUjxZWhq9aHwqoUuF5P22qjQMLKvnKW4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:reply-to:in-reply-to:references:from:date:message-id :subject:to:cc:content-type:content-transfer-encoding; b=kbVuFguWMP2/iAUQkJ/uPl4SDo1R22GnwrnObFR9Gdp6mBJQ7Ng8oKq1Yz3MoEkNpb NlQQ5M3GyE/8xV274egIckvyKGLNBr7t8zK1gVrJVeimk12gIepH0FgnY044DXMUqgRP bNe0upwQUBmyQPRGKyna296qAooevowj8fadM= Received: by 10.229.235.4 with SMTP id ke4mr15716790qcb.63.1293804786150; Fri, 31 Dec 2010 06:13:06 -0800 (PST) MIME-Version: 1.0 Received: by 10.229.100.130 with HTTP; Fri, 31 Dec 2010 06:12:45 -0800 (PST) Reply-To: RQuadling@googlemail.com In-Reply-To: References: Date: Fri, 31 Dec 2010 14:12:45 +0000 Message-ID: To: Kalle Sommer Nielsen Cc: PHP internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Working with arrays. From: rquadling@gmail.com (Richard Quadling) On 31 December 2010 14:08, Kalle Sommer Nielsen wrote: > Hi Richard > > 2010/12/31 Richard Quadling : >> Hi. >> >> What macros exist regarding processing arrays in PHP (core not userland)= ? > > Zend hash, see Zend/zend_hash.c for its API. > >> I want to pass ... >> >> array('value1', 'value2', 'value3') > > You would do something like: > > PHP_FUNCTION(test) > { > =C2=A0 =C2=A0 =C2=A0 zval *array; > > =C2=A0 =C2=A0 =C2=A0 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,= "a", > &array) =3D=3D FAILURE) { > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return; > =C2=A0 =C2=A0 =C2=A0 } > > =C2=A0 =C2=A0 =C2=A0 /* Z_ARRVAL_P(array) is a HashTable* ptr */ > } > >> >> to a function and in the function have it converted to >> >> 'value1\0value2\0value3\0\0'. >> >> Conventionally, I'd need to iterate the array to get the lengths of >> all the elements, add the number of elements to this value and then 1 >> more for the trailing \0. > > The move_forward, get_current etc. hash functions can be used to > iterate, see zend_hash.h: > http://lxr.php.net/opengrok/xref/PHP_TRUNK/Zend/zend_hash.h#194 > > > -- > regards, > > Kalle Sommer Nielsen > kalle@php.net > OOI, can I cheat and simply use php_implode() ? --=20 Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY