cvs: /php4 ChangeLog /php4/ext/standard basic_functions.c basic_functions.h

From: Date: Mon, 20 Sep 1999 10:09:58 +0000
Subject: cvs: /php4 ChangeLog /php4/ext/standard basic_functions.c basic_functions.h
Groups: php.version4 
Request: Send a blank email to php-version4+get-4651@lists.php.net to get a copy of this message
thies Mon Sep 20 06:09:58 1999 EDT Modified files: /php4 ChangeLog /php4/ext/standard basic_functions.c basic_functions.h Log: added array_count_values function. Index: php4/ChangeLog diff -u php4/ChangeLog:1.115 php4/ChangeLog:1.116 --- php4/ChangeLog:1.115 Sun Sep 19 07:07:49 1999 +++ php4/ChangeLog Mon Sep 20 06:09:57 1999 @@ -2,6 +2,7 @@ ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ?? 1999, Version 4.0 Beta 3 +- Added array_count_values() function. (Thies) - snmp, pgsql, mysql and gd modules can be built as dynamically loaded modules (Greg) - OCI8 fix for fetching empty LOBs (Thies) Index: php4/ext/standard/basic_functions.c diff -u php4/ext/standard/basic_functions.c:1.88 php4/ext/standard/basic_functions.c:1.89 --- php4/ext/standard/basic_functions.c:1.88 Wed Sep 15 05:51:20 1999 +++ php4/ext/standard/basic_functions.c Mon Sep 20 06:09:57 1999 @@ -337,6 +337,7 @@ PHP_FE(array_merge, NULL) PHP_FE(array_keys, NULL) PHP_FE(array_values, NULL) + PHP_FE(array_count_values, NULL) PHP_FE(connection_aborted, NULL) PHP_FE(connection_timeout, NULL) @@ -3239,6 +3240,66 @@ sizeof(zval *), NULL); zend_hash_move_forward(input->value.ht); + } +} +/* }}} */ + +/* {{{ proto array array_count_values(array input) + Return the value as key and the frequency of that value in <input> as value */ +PHP_FUNCTION(array_count_values) +{ + zval **input, /* Input array */ + **entry; /* An entry in the input array */ + zval **tmp; + HashTable *myht; + + /* Get arguments and do error-checking */ + if (ARG_COUNT(ht) != 1 || getParametersEx(1, &input) == FAILURE) { + WRONG_PARAM_COUNT; + } + + if ((*input)->type != IS_ARRAY) { + zend_error(E_WARNING, "Argument to array_count_values() should be an array"); + return; + } + + /* Initialize return array */ + array_init(return_value); + + /* Go through input array and add values to the return array */ + myht = (*input)->value.ht; + zend_hash_internal_pointer_reset(myht); + while (zend_hash_get_current_data(myht, (void **)&entry) == SUCCESS) { + if ((*entry)->type == IS_LONG) { + if (zend_hash_index_find(return_value->value.ht, + (*entry)->value.lval, + (void**)&tmp) == FAILURE) { + zval *data; + MAKE_STD_ZVAL(data); + data->type = IS_LONG; + data->value.lval = 1; + zend_hash_index_update(return_value->value.ht,(*entry)->value.lval, &data, sizeof(data), NULL); + } else { + (*tmp)->value.lval++; + } + } else if ((*entry)->type == IS_STRING) { + if (zend_hash_find(return_value->value.ht, + (*entry)->value.str.val, + (*entry)->value.str.len+1, + (void**)&tmp) == FAILURE) { + zval *data; + MAKE_STD_ZVAL(data); + data->type = IS_LONG; + data->value.lval = 1; + zend_hash_update(return_value->value.ht,(*entry)->value.str.val,(*entry)->value.str.len + 1, &data, sizeof(data), NULL); + } else { + (*tmp)->value.lval++; + } + } else { + zend_error(E_WARNING, "Can only count STRING and INTEGER values!"); + } + + zend_hash_move_forward(myht); } } /* }}} */ Index: php4/ext/standard/basic_functions.h diff -u php4/ext/standard/basic_functions.h:1.14 php4/ext/standard/basic_functions.h:1.15 --- php4/ext/standard/basic_functions.h:1.14 Sat Sep 4 17:10:39 1999 +++ php4/ext/standard/basic_functions.h Mon Sep 20 06:09:57 1999 @@ -29,7 +29,7 @@ */ -/* $Id: basic_functions.h,v 1.14 1999/09/04 21:10:39 rasmus Exp $ */ +/* $Id: basic_functions.h,v 1.15 1999/09/20 10:09:57 thies Exp $ */ #ifndef _BASIC_FUNCTIONS_H #define _BASIC_FUNCTIONS_H @@ -141,6 +141,7 @@ PHP_FUNCTION(array_merge); PHP_FUNCTION(array_keys); PHP_FUNCTION(array_values); +PHP_FUNCTION(array_count_values); #if HAVE_PUTENV typedef struct {

« previous php.version4 (#4651) next »