php實戰C擴充套件之陣列
阿新 • • 發佈:2018-11-28
近來看了php的c擴充套件書寫,嘗試接入陣列處理,學會了幾個HashTable處理函式記錄如下:
zend_hash_next_index_insert 插入資料(數字陣列或者關聯陣列);
zend_hash_add 插入關聯陣列
zend_hash_index_update 數字陣列或者關聯陣列
zend_hash_update 更新關聯陣列
程式碼:
zval *arr, *prefix, *entry,;
zend_string *string_key;
zend_ulong num_key;
int a;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "aa", &arr, &prefix) == FAILURE) {
return;
}
a = zend_hash_num_elements(Z_ARRVAL_P(arr)) + zend_hash_num_elements(Z_ARRVAL_P(prefix));
array_init_size(return_value,a );
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(arr), num_key, string_key, entry) {
zend_hash_next_index_insert(Z_ARRVAL_P(return_value), entry);
} ZEND_HASH_FOREACH_END();