CVS update: php4/ext/standard

From: Date: Sat, 05 Jun 1999 21:19:25 +0000
Subject: CVS update: php4/ext/standard
Groups: php.version4 
Request: Send a blank email to php-version4+get-1303@lists.php.net to get a copy of this message
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 {

« previous php.version4 (#1303) next »