Finding key in a hash...

From: Date: Thu, 11 Apr 2002 15:13:07 +0000
Subject: Finding key in a hash...
Groups: php.dev 
Request: Send a blank email to php-dev+get-82577@lists.php.net to get a copy of this message
I am trying to determine if a key exists in a hash that has been passed to my function. I couldn't find much information on finding how to do it, but from greping the source I managed to come up with the following. Problem is it doesn't work *heh*. All I want to do is check whether the key exists or not and act appropriately. My code compiles fine, but the zend_hash_exists() test always returns false. The A facsimile of my code follows: ----------------------------------------------------------------------- ZEND_FUNCTION( foofunction ){ zval **paramHash = NULL; zval *aHash = NULL; if( ZEND_NUM_ARGS() != 1 ||zend_get_parameters_ex( ZEND_NUM_ARGS(), &paramHash ) == FAILURE ){ WRONG_PARAM_COUNT; } aHash = *paramHash; if( zend_hash_exists( aHash->value.ht, "foo", sizeof( "foo" ) ) ){ // // Do something here. // } else{ // // Do something else here. // } } ----------------------------------------------------------------------- In my PHP code I have the following: ----------------------------------------------------------------------- $aHash = array(); $aHash['foo'] = 'fee'; foofunction( $aHash ); ----------------------------------------------------------------------- Cheers, Rob. -- .-----------------. | Robert Cummings | :-----------------`----------------------------. | Webdeployer - Chief PHP and Java Programmer | :----------------------------------------------: | Mail : mailto:robert.cummings@webmotion.com | | Phone : (613) 731-4046 x.109 | :----------------------------------------------: | Website : http://www.webmotion.com | | Fax : (613) 260-9545 | `----------------------------------------------'

« previous php.dev (#82577) next »