?? ??? 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)
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
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);
HashTable *hash;
int argc, i, c;
Bucket ***lists, **list, ***ptrs, *p;
- zval *entry;
/* Get the argument count and check it */
argc = ARG_COUNT(ht);
}
/* }}} */
+/* {{{ 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);
+ }
+ }
+}
+
+/* }}} */
+
/*
* Local variables:
* tab-width: 4
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)
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);