diff options
author | Andrei Zmievski <andrei@php.net> | 2002-01-10 21:31:06 +0000 |
---|---|---|
committer | Andrei Zmievski <andrei@php.net> | 2002-01-10 21:31:06 +0000 |
commit | ddc039d0f53dba65dc32e14732249a95bd9d1b01 (patch) | |
tree | 2e16423a6493544135d4d408ebba9af7eef19a4e /ext/standard/array.c | |
parent | 645a94cd5e9e7e3de841802062bfe67589aab088 (diff) | |
download | php-git-ddc039d0f53dba65dc32e14732249a95bd9d1b01.tar.gz |
Fix the recursive counting, it was broken for associative or non-sequential
arrays. Also update NEWS file.
Diffstat (limited to 'ext/standard/array.c')
-rw-r--r-- | ext/standard/array.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/ext/standard/array.c b/ext/standard/array.c index 86331a75e8..a1daeacecd 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -230,7 +230,7 @@ PHP_FUNCTION(ksort) int php_count_recursive(zval *array, long mode) { - long cnt = 0, i; + long cnt = 0; zval **element; HashTable *target_hash; @@ -240,13 +240,16 @@ int php_count_recursive(zval *array, long mode) { cnt += zend_hash_num_elements(target_hash); if (mode == COUNT_RECURSIVE) { - for(i = 0; i < zend_hash_num_elements(target_hash); i++) { - if (zend_hash_index_find (Z_ARRVAL_P(array), i, (void **) &element) == SUCCESS) { - cnt += php_count_recursive(*element, COUNT_RECURSIVE); - } + HashPosition pos; + + for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(array), &pos); + zend_hash_get_current_data_ex(Z_ARRVAL_P(array), (void **) &element, &pos) == SUCCESS; + zend_hash_move_forward_ex(Z_ARRVAL_P(array), &pos)) { + cnt += php_count_recursive(*element, COUNT_RECURSIVE); } } } + return cnt; } |