Re: Working with arrays.

From: Date: Fri, 31 Dec 2010 14:12:45 +0000
Subject: Re: Working with arrays.
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-51155@lists.php.net to get a copy of this message
On 31 December 2010 14:08, Kalle Sommer Nielsen <kalle@php.net> wrote: > Hi Richard > > 2010/12/31 Richard Quadling <rquadling@gmail.com>: >> 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) > { >       zval *array; > >       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", > &array) == FAILURE) { >              return; >       } > >       /* 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() ? -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

« previous php.internals (#51155) next »