Using zend_hash_find when key is of Integer type

View: New views
5 Messages — Rating Filter:   Alert me  

Using zend_hash_find when key is of Integer type

by Ambrish :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi All,

I am writing a PHP extension and over here I am trying to use zend_hash_find API to search for key in a hash. But the problem here is "my key is an integer and not *char". So this zend_hash_find will not work.

There is a way by which I can do it. See the following code.
for ( i = 0; i < numOpts; i++) {
        zend_hash_get_current_key(Z_ARRVAL_P(zval), &opt_key, &num_idx, 1);
        zend_hash_get_current_data(Z_ARRVAL_P(zval), (void**)&data);

        if (Z_TYPE_PP(data) == IS_STRING) {
                option_str = Z_STRVAL_PP(data);
        } else {
                option_num = Z_LVAL_PP(data);
        }

        /* further implementation. */
       
        zend_hash_move_forward(Z_ARRVAL_P(zval));
}
But this approach is inefficient as I have to iterate complete Hash to get one key-value and in my case I know the key before iterating.

Is there any other better approach to do this?

Regards,
Ambrish Bhargava

Re: Using zend_hash_find when key is of Integer type

by Antony Dovgal-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 03.07.2008 05:35, Ambrish wrote:
> Hi All,
>
> I am writing a PHP extension and over here I am trying to use zend_hash_find
> API to search for key in a hash. But the problem here is "my key is an
> integer and not *char". So this zend_hash_find will not work.

Use zend_hash_index_find() then?

--
Wbr,
Antony Dovgal

--
PECL development discussion Mailing List (http://pecl.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: Using zend_hash_find when key is of Integer type

by Ambrish :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I can not use zend_hash_index_find() because I do not know the index of the key.

Regards,
Ambrish Bhargava

Antony Dovgal-3 wrote:
On 03.07.2008 05:35, Ambrish wrote:
> Hi All,
>
> I am writing a PHP extension and over here I am trying to use zend_hash_find
> API to search for key in a hash. But the problem here is "my key is an
> integer and not *char". So this zend_hash_find will not work.

Use zend_hash_index_find() then?

--
Wbr,
Antony Dovgal

--
PECL development discussion Mailing List (http://pecl.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Using zend_hash_find when key is of Integer type

by Derick Rethans :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, 3 Jul 2008, Ambrish wrote:

> I can not use zend_hash_index_find() because I do not know the index of the
> key.

Sure you do, the key is the index.

regards,
Derick

--
Derick Rethans
http://derickrethans.nl | http://ezcomponents.org | http://xdebug.org

--
PECL development discussion Mailing List (http://pecl.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: Using zend_hash_find when key is of Integer type

by Antony Dovgal-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 03.07.2008 12:58, Ambrish wrote:
> Hi,
>
> I can not use zend_hash_index_find() because I do not know the index of the
> key.

In this particular case "index" means "integer key".

--
Wbr,
Antony Dovgal

--
PECL development discussion Mailing List (http://pecl.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

LightInTheBox - Buy quality products at wholesale price