# Working with arrays.

- Thread: https://externals.io/message/51152
- Original archive: https://news-web.php.net/php.internals/51152
- Started by Richard Quadling on 2010-12-31T13:48:59+00:00
- Messages: 5
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #51152 — Richard Quadling — 2010-12-31T13:48:59+00:00

URL: https://externals.io/message/51152#51152

Hi.

What macros exist regarding processing arrays in PHP (core not userland)?

I want to pass ...

array('value1', 'value2', 'value3')

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.

Unless there are some macros to allow to do this sort of thing more easily.

Regards,

Richard Quadling.

-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

---

## #51154 — Kalle Sommer Nielsen — 2010-12-31T14:08:33+00:00

URL: https://externals.io/message/51152#51154 · In reply to: #51152

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

---

## #51155 — Richard Quadling — 2010-12-31T14:12:45+00:00

URL: https://externals.io/message/51152#51155 · In reply to: #51154

> Hi Richard
>
> 2010/12/31 Richard Quadling <rquadling@gmail.com>:
> > […]
>
> Zend hash, see Zend/zend_hash.c for its API.
>
> > […]
>
> 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 */
> }
>
> > […]
>
> 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

---

## #51156 — mark skilbeck — 2010-12-31T14:20:08+00:00

URL: https://externals.io/message/51152#51156 · In reply to: #51152

I did it like so:
bitbucket.org/winapiforphp/system/src/93583820bbc1/winsystem_registry.c#cl-298

It's a little messy.


>
> Hi.
>
> What macros exist regarding processing arrays in PHP (core not userland)?
>
> I want to pass ...
>
> array('value1', 'value2', 'value3')
>
> 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.
>
> Unless there are some macros to allow to do this sort of thing more easily.
>
> Regards,
>
> Richard Quadling.
>
> --
> Richard Quadling
> Twitter : EE : Zend
> @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY
>
> --
> 
> 
>



--
Mark Skilbeck.
http://blog.mahcuz.com - webmaster
http://bytes.com - PHP Forum Moderator

---

## #51157 — Richard Quadling — 2010-12-31T14:49:59+00:00

URL: https://externals.io/message/51152#51157

> I did it like
> so: https://bitbucket.org/winapiforphp/system/src/93583820bbc1/winsystem_registry.c#cl-298
> It's a little messy.

I got that. 4 times no less.

-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY
