PHP扩展检查密钥是否存在

时间:2016-11-15 19:54:48

标签: php c php-extension

我实际上是编写扩展php(它在C中的wirte)。有什么方法可以知道关键数组中是否存在键?我使用add_assoc_string但是如果密钥存在,此函数会擦除数据。目前我这样做:

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,但我找不到任何例子。

修改

我最终找到解决方案,检查{I}中是否存在密钥

zaval array

1 个答案:

答案 0 :(得分:1)

您可以从php-src使用angular.module('app').controller('channelAoiEditor', function ($scope, datastore, $cookieStore, modalWindow, nospace) {

zend_hash_index_exists(Z_ARRVAL_P(return_value))开始的函数系列只是简化array_使用的包装器。查看zend hash table API的源代码。你会看到它引用array_init()。所以只需在代码中使用适当的类型转换。

更多示例如何使用phpinternalsbook中的数组/ hast表。 您也可以直接在PHP源代码repo中找到许多有用的示例。例如,对于这种特殊情况 - here

PS:此外,看起来此代码无效:

zend_hash_init()

因为真正的签名是... add_index_long(return_value, "key1", "value", 1); ,所以不能使用" key1"作为add_index_long(zval *arg, zend_ulong idx, zend_long n)和"值"由于类型不匹配而导致zend_ulong idx

相关问题