mirror of
https://github.com/php/php-src.git
synced 2025-08-16 14:08:47 +02:00
Added array_merge() function.
This commit is contained in:
parent
2db1d61718
commit
f8f8defb42
2 changed files with 59 additions and 0 deletions
|
@ -303,6 +303,7 @@ function_entry basic_functions[] = {
|
||||||
PHP_FE(unshift, first_arg_force_ref)
|
PHP_FE(unshift, first_arg_force_ref)
|
||||||
PHP_FE(splice, first_arg_force_ref)
|
PHP_FE(splice, first_arg_force_ref)
|
||||||
PHP_FE(slice, NULL)
|
PHP_FE(slice, NULL)
|
||||||
|
PHP_FE(array_merge, NULL)
|
||||||
|
|
||||||
{NULL, NULL, NULL}
|
{NULL, NULL, NULL}
|
||||||
};
|
};
|
||||||
|
@ -2827,6 +2828,63 @@ PHP_FUNCTION(slice)
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
|
||||||
|
/* {{{ 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);
|
||||||
|
}
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Local variables:
|
* Local variables:
|
||||||
* tab-width: 4
|
* tab-width: 4
|
||||||
|
|
|
@ -128,6 +128,7 @@ PHP_FUNCTION(shift);
|
||||||
PHP_FUNCTION(unshift);
|
PHP_FUNCTION(unshift);
|
||||||
PHP_FUNCTION(splice);
|
PHP_FUNCTION(splice);
|
||||||
PHP_FUNCTION(slice);
|
PHP_FUNCTION(slice);
|
||||||
|
PHP_FUNCTION(array_merge);
|
||||||
|
|
||||||
#if HAVE_PUTENV
|
#if HAVE_PUTENV
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue