Re: [PHP4BETA] CVS update: php4/ext/standard

From: Date: Sun, 06 Jun 1999 04:28:39 +0000
Subject: Re: [PHP4BETA] CVS update: php4/ext/standard
Groups: php.version4 
Request: Send a blank email to php-version4+get-1316@lists.php.net to get a copy of this message
There's a function called hash_merge which might be of better use here than doing it yourself. void zend_hash_merge(HashTable *target, HashTable *source, void (*pCopyConstructor) (void *pData), void *tmp, uint size, int overwrite); Hope I'm not being annoying, but it's good for you guys to know what functions are out there so that you won't implement them a second time. Andi At 21:19 05/06/99 +0000, andrey wrote:
Date: Saturday June 5, 1999 @ 17:19 Author: andrey Update of /repository/php4/ext/standard In directory php:/tmp/cvs-serv15528/ext/standard Modified Files:
        basic_functions.c basic_functions.h
Log Message: Added array_merge() function. Index: php4/ext/standard/basic_functions.c diff -u php4/ext/standard/basic_functions.c:1.25 php4/ext/standard/basic_functions.c:1.26
--- php4/ext/standard/basic_functions.c:1.25    Sat Jun  5 16:43:36 1999
+++ php4/ext/standard/basic_functions.c Sat Jun 5 17:19:25 1999 @@ -303,6 +303,7 @@
        PHP_FE(unshift, first_arg_force_ref)
        PHP_FE(splice, first_arg_force_ref)
        PHP_FE(slice,                                           NULL)
+       PHP_FE(array_merge,                                     NULL)
        {NULL, NULL, NULL}
}; @@ -2823,6 +2824,63 @@
                pos++;
                zend_hash_move_forward(input->value.ht);
        }
+} +/* }}} */ + + +/* {{{ proto array array_merge(array arr1 [, array arr2, ...]) + Merges elements from passed arrays into one array */ +PHP_FUNCTION(array_merge) +{
+       zval       **args = NULL,
+                          **entry;
+       HashTable       *hash;
+       int                     argc,
+                               i;
+       char            *string_key;
+       ulong           num_key;
+
+       /* Get the argument count and check it */
+       argc = ARG_COUNT(ht);
+       if (argc < 2) {
+               WRONG_PARAM_COUNT;
+       }
+
+       /* Allocate arguments array and get the arguments, checking for errors. */
+       args = (zval **)emalloc(argc * sizeof(zval *));
+       if (getParametersArray(ht, argc, args) == FAILURE) {
+               efree(args);
+               WRONG_PARAM_COUNT;
+       }
+
+       array_init(return_value);
+
+       for (i=0; i<argc; i++) {
+               convert_to_array(args[i]);
+               hash = args[i]->value.ht;
+
+               zend_hash_internal_pointer_reset(hash);
+               while(zend_hash_get_current_data(hash, (void **)&entry) == SUCCESS) {
+                       (*entry)->refcount++;
+
+                       switch (zend_hash_get_current_key(hash, &string_key, &num_key)) {
+                               case HASH_KEY_IS_STRING:
+ zend_hash_update(return_value->value.ht, string_key, strlen(string_key)+1,
+ entry, sizeof(zval *), NULL);
+                                       efree(string_key);
+                                       break;
+
+                               case HASH_KEY_IS_LONG:
+ zend_hash_next_index_insert(return_value->value.ht,
+                     entry, sizeof(zval *), NULL);
+                                       break;
+                       }
+
+                       zend_hash_move_forward(hash);
+               }
+       }
+
+       efree(args);
} /* }}} */ Index: php4/ext/standard/basic_functions.h diff -u php4/ext/standard/basic_functions.h:1.7 php4/ext/standard/basic_functions.h:1.8
--- php4/ext/standard/basic_functions.h:1.7     Sat Jun  5 16:43:36 1999
+++ php4/ext/standard/basic_functions.h Sat Jun 5 17:19:25 1999 @@ -29,7 +29,7 @@ */ -/* $Id: basic_functions.h,v 1.7 1999/06/05 20:43:36 andrey Exp $ */ +/* $Id: basic_functions.h,v 1.8 1999/06/05 21:19:25 andrey Exp $ */ #ifndef _BASIC_FUNCTIONS_H #define _BASIC_FUNCTIONS_H @@ -128,6 +128,7 @@ PHP_FUNCTION(unshift); PHP_FUNCTION(splice); PHP_FUNCTION(slice); +PHP_FUNCTION(array_merge); #if HAVE_PUTENV typedef struct { -- PHP 4 Beta
--- Andi Gutmans <andi@zend.com> ICQ: 1568297

« previous php.version4 (#1316) next »