Re: In C, how do I access an associative array?
| From: | Stig Venaas | Date: | Tue, 25 Sep 2001 13:18:24 +0000 |
| Subject: | Re: In C, how do I access an associative array? | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-66541@lists.php.net to get a copy of this message | ||
On Tue, Sep 25, 2001 at 09:00:18AM -0400, mlwmohawk@mohawksoft.com wrote:
>
> If I do this in PHP:
>
> <?
> $array = array();
>
> $array["foo"] = "bar";
> $array["hey"] = "you";
> $array["pink"]="floyd";
>
> myext_function($array);
> ?>
>
>
> How do I find all the keys and values out of that array in my extension?
> Is there a way?
You can do something like:
if (zend_hash_find(Z_ARRVAL_PP(input), "pink", sizeof("pink"), (void **)
&val) == SUCCESS) {
convert_to_string_ex(val);
...
}
to look for pink, if you just want to iterate through the keys you can do
something like:
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(input), &pos);
while(zend_hash_get_current_data_ex(Z_ARRVAL_PP(input), (void **)&entry, &pos) == SUCCESS) {
zend_hash_get_current_key_ex(Z_ARRVAL_PP(input), &string_key, &string_key_len,
&num_key, 0, &pos)
...
}
See docs or sources for details/examples
Stig