cvs: php4 / NEWS /ext/standard array.c
| From: | Andrei Zmievski | Date: | Thu, 10 Jan 2002 21:31:08 +0000 |
| Subject: | cvs: php4 / NEWS /ext/standard array.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-9035@lists.php.net to get a copy of this message | ||
andrei Thu Jan 10 16:31:08 2002 EDT
Modified files:
/php4 NEWS
/php4/ext/standard array.c
Log:
Fix the recursive counting, it was broken for associative or non-sequential
arrays. Also update NEWS file.
Index: php4/NEWS
diff -u php4/NEWS:1.844 php4/NEWS:1.845
--- php4/NEWS:1.844 Wed Jan 9 18:59:04 2002
+++ php4/NEWS Thu Jan 10 16:31:06 2002
@@ -1,7 +1,9 @@
PHP 4 NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? 200?, Version 4.2.0-dev
-- added mb_get_info() to get internal settings of mbstring.
+- Added second parameter to count() that can be used to specify either normal
+ or recursive counting. (patch by Vlad Bosinceanu <glipy@fx.ro>)
+- Added mb_get_info() to get internal settings of mbstring.
- Added async query functions to PostgreSQL module (Yasuo)
- Added pg_copy_to()/pg_copy_from() for PostgreSQL module (Youichi, Yasuo)
- Added IPv6 support in FTP extension. (Stig Venaas)
Index: php4/ext/standard/array.c
diff -u php4/ext/standard/array.c:1.152 php4/ext/standard/array.c:1.153
--- php4/ext/standard/array.c:1.152 Wed Jan 9 11:03:34 2002
+++ php4/ext/standard/array.c Thu Jan 10 16:31:06 2002
@@ -21,7 +21,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: array.c,v 1.152 2002/01/09 16:03:34 derick Exp $ */
+/* $Id: array.c,v 1.153 2002/01/10 21:31:06 andrei Exp $ */
#include "php.h"
#include "php_ini.h"
@@ -230,7 +230,7 @@
int php_count_recursive(zval *array, long mode)
{
- long cnt = 0, i;
+ long cnt = 0;
zval **element;
HashTable *target_hash;
@@ -240,13 +240,16 @@
{
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;
}