我實際上是爲擴展php編寫代碼(它在C
中是wirte)。任何方式來知道關聯數組中是否存在關鍵字?我使用add_assoc_string
,但是如果密鑰存在,此功能將擦除數據。目前我這樣做:PHP擴展檢查是否存在密鑰
array_init(return_value);
add_index_long(return_value, "key1", "value", 1);
add_index_long(return_value, "key2", "value6", 1);
add_index_long(return_value, "key1", "value2", 1); //here I erase previous key1 by value2
是否有可能檢查key1例如是否存在?也許我可以使用hashTable
但我找不到任何示例。
編輯
我已經finaly找到解決方案,以檢查是否鑰匙zaval array
存在我做
if(zend_hash_exists(Z_ARRVAL_P(return_value), "key", sizeof("key"))){
//key exist
}
錯字:「ckeck」 - >「check」 – Vasif