cvs: php4 / NEWS TODO /ext/standard array.c basic_functions.c php_array.h
| From: | Andrei Zmievski | Date: | Wed, 25 Oct 2000 17:40:12 +0000 |
| Subject: | cvs: php4 / NEWS TODO /ext/standard array.c basic_functions.c php_array.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-2257@lists.php.net to get a copy of this message | ||
andrei Wed Oct 25 10:40:12 2000 EDT
Modified files:
/php4/ext/standard array.c php_array.h basic_functions.c
/php4 TODO NEWS
Log:
Added array_sum() function.
Index: php4/ext/standard/array.c
diff -u php4/ext/standard/array.c:1.78 php4/ext/standard/array.c:1.79
--- php4/ext/standard/array.c:1.78 Sun Oct 22 04:18:21 2000
+++ php4/ext/standard/array.c Wed Oct 25 10:40:10 2000
@@ -20,7 +20,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: array.c,v 1.78 2000/10/22 11:18:21 venaas Exp $ */
+/* $Id: array.c,v 1.79 2000/10/25 17:40:10 andrei Exp $ */
#include "php.h"
#include "php_ini.h"
@@ -2276,7 +2276,6 @@
HashTable *hash;
int argc, i, c = 0;
Bucket ***lists, **list, ***ptrs, *p;
- zval *entry;
/* Get the argument count and check it */
argc = ARG_COUNT(ht);
@@ -2383,7 +2382,6 @@
HashTable *hash;
int argc, i, c;
Bucket ***lists, **list, ***ptrs, *p;
- zval *entry;
/* Get the argument count and check it */
argc = ARG_COUNT(ht);
@@ -2768,6 +2766,43 @@
zend_hash_move_forward(Z_ARRVAL_PP(input));
}
}
+/* }}} */
+
+/* {{{ proto mixed array_sum(array input)
+ Returns the sum of the array entries */
+
+PHP_FUNCTION(array_sum)
+{
+ zval **input,
+ **entry;
+ int argc = ZEND_NUM_ARGS();
+
+ if (argc != 1 || zend_get_parameters_ex(argc, &input) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+
+ ZVAL_LONG(return_value, 0);
+
+ for (zend_hash_internal_pointer_reset(Z_ARRVAL_PP(input));
+ zend_hash_get_current_data(Z_ARRVAL_PP(input), (void **)&entry) == SUCCESS;
+ zend_hash_move_forward(Z_ARRVAL_PP(input))) {
+
+ if (Z_TYPE_PP(entry) == IS_ARRAY || Z_TYPE_PP(entry) == IS_OBJECT)
+ continue;
+
+ SEPARATE_ZVAL(entry);
+ convert_scalar_to_number(*entry);
+
+ if (Z_TYPE_PP(entry) == IS_LONG && Z_TYPE_P(return_value) == IS_LONG) {
+ Z_LVAL_P(return_value) += Z_LVAL_PP(entry);
+ } else {
+ convert_to_double(return_value);
+ convert_to_double_ex(entry);
+ Z_DVAL_P(return_value) += Z_DVAL_PP(entry);
+ }
+ }
+}
+
/* }}} */
/*
Index: php4/ext/standard/php_array.h
diff -u php4/ext/standard/php_array.h:1.16 php4/ext/standard/php_array.h:1.17
--- php4/ext/standard/php_array.h:1.16 Sun Jul 23 18:39:49 2000
+++ php4/ext/standard/php_array.h Wed Oct 25 10:40:10 2000
@@ -19,7 +19,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_array.h,v 1.16 2000/07/24 01:39:49 david Exp $ */
+/* $Id: php_array.h,v 1.17 2000/10/25 17:40:10 andrei Exp $ */
#ifndef PHP_ARRAY_H
#define PHP_ARRAY_H
@@ -72,6 +72,7 @@
PHP_FUNCTION(array_unique);
PHP_FUNCTION(array_intersect);
PHP_FUNCTION(array_diff);
+PHP_FUNCTION(array_sum);
HashTable* php_splice(HashTable *, int, int, zval ***, int, HashTable **);
int multisort_compare(const void *a, const void *b);
Index: php4/ext/standard/basic_functions.c
diff -u php4/ext/standard/basic_functions.c:1.268 php4/ext/standard/basic_functions.c:1.269
--- php4/ext/standard/basic_functions.c:1.268 Sun Oct 22 07:41:02 2000
+++ php4/ext/standard/basic_functions.c Wed Oct 25 10:40:10 2000
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: basic_functions.c,v 1.268 2000/10/22 14:41:02 sas Exp $ */
+/* $Id: basic_functions.c,v 1.269 2000/10/25 17:40:10 andrei Exp $ */
#include "php.h"
#include "php_main.h"
@@ -549,6 +549,7 @@
PHP_FE(array_unique, NULL)
PHP_FE(array_intersect, NULL)
PHP_FE(array_diff, NULL)
+ PHP_FE(array_sum, NULL)
/* aliases from array.c */
PHP_FALIAS(pos, current, first_arg_force_ref)
Index: php4/TODO
diff -u php4/TODO:1.102 php4/TODO:1.103
--- php4/TODO:1.102 Fri Oct 20 08:53:16 2000
+++ php4/TODO Wed Oct 25 10:40:11 2000
@@ -77,7 +77,7 @@
ext/standard
------------
- * array_sum(), array_mean()
+ * array_mean()
* add a version number to data serialized via serialize().
* array_add(). (Andrei)
* possibly modify parsing of GPC data to automatically create arrays if
Index: php4/NEWS
diff -u php4/NEWS:1.490 php4/NEWS:1.491
--- php4/NEWS:1.490 Mon Oct 23 06:15:48 2000
+++ php4/NEWS Wed Oct 25 10:40:11 2000
@@ -3,6 +3,7 @@
?? ??? 2000, Version 4.0.4
+- Added array_sum() function. (Andrei)
- Fixed a bug in session.c. The php_session_save_current_state did not check
if mod_data is NULL and such situation is possible if the user calls
session_module_name with a parameter. (alex@zend.com)