- 論壇徽章:
- 0
|
- PHP_FUNCTION(list_clean)
- {
- zval *z_array; /* 外部傳入的數(shù)組 */
- zval **z_item; /* 一級數(shù)組單元 */
- zval **zz_item; /* 二級數(shù)組單元 */
-
- int len, len1;
- int i, i1;
- int tag = 0;
- if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &z_array)) {
- return;
- }
-
- array_init(return_value);
- /* 獲取數(shù)組大小 */
- len = zend_hash_num_elements(Z_ARRVAL_P(z_array));
- /* 將數(shù)組的內(nèi)部指針指向第一個單元 */
- zend_hash_internal_pointer_reset(Z_ARRVAL_P(z_array));
- for (i = 0; i < len; i ++) {
- char* key;
- int idx;
- /* 獲取當前數(shù)據(jù) */
- zend_hash_get_current_data(Z_ARRVAL_P(z_array), (void**) &z_item);
- convert_to_array_ex(z_item);
-
- if (zend_hash_get_current_key(Z_ARRVAL_P(z_array), &key, &idx, 0) == HASH_KEY_IS_STRING) {
- /* KEY為字符串 */
- return;
- } else {
- int breakTag = 0;
- /* KEY為數(shù)字 */
- zval *temp_value;
- MAKE_STD_ZVAL(temp_value);
- array_init(temp_value); /* 存儲組成return_value的中間數(shù)組 */
- len1 = zend_hash_num_elements(Z_ARRVAL_P(*z_item));
- zend_hash_internal_pointer_reset(Z_ARRVAL_P(*z_item));
- for(i1=0; i1<len1; i1++){
- char* key1;
- int idx1;
- /* 獲取當前數(shù)據(jù) */
- zend_hash_get_current_data(Z_ARRVAL_P(*z_item), (void**) &zz_item);
- convert_to_string_ex(zz_item);
- if (zend_hash_get_current_key(Z_ARRVAL_P(*z_item), &key1, &idx1, 0) == HASH_KEY_IS_STRING){
- add_assoc_string(return_value, key1, Z_STRVAL_PP(zz_item), 1);
- //add_next_index_string(return_value, Z_STRVAL_PP(zz_item), 1);
- // add_next_index_string(return_value, key1, 1);
- }else{
- return;
- }
- zend_hash_move_forward(Z_ARRVAL_P(*z_item));
- }
- //add_index_zval(return_value, tag, temp_value);
- tag++;
- zval_ptr_dtor(&temp_value); /* 釋放資源 */
- }
- /* 將數(shù)組中的內(nèi)部指針向前移動一位 */
- zend_hash_move_forward(Z_ARRVAL_P(z_array));
- }
- }
復(fù)制代碼 用c定義了個叫l(wèi)ist_clean的php函數(shù),在php中寫的測試代碼如圖:
測試代碼.jpg (59.47 KB, 下載次數(shù): 31)
下載附件
2013-10-30 14:02 上傳
當我注釋掉46、48行,保留47行代碼時,
測試結(jié)果如圖:
addnextvalue.jpg (24.47 KB, 下載次數(shù): 30)
下載附件
2013-10-30 14:04 上傳
說明Z_STRVAL_PP(zz_item)值是沒問題的
當我注釋掉46、47行,保留48行時,
測試結(jié)果如圖:
addnextkey.jpg (27.6 KB, 下載次數(shù): 30)
下載附件
2013-10-30 14:06 上傳
說明索引key1也是沒問題的
但當我保留46行,注釋掉47、48行時
測試結(jié)果如圖:
綜合.jpg (23.78 KB, 下載次數(shù): 32)
下載附件
綜合
2013-10-30 14:12 上傳
這時的結(jié)果就出問題了
有哪位大神能指點迷津卜/ |
|