Add `putAll()`.
This commit is contained in:
parent
a92c3022e8
commit
ecfee75fbe
|
@ -1251,7 +1251,22 @@ PHP_METHOD(Collection, plusValuesAssign)
|
||||||
|
|
||||||
PHP_METHOD(Collection, putAll)
|
PHP_METHOD(Collection, putAll)
|
||||||
{
|
{
|
||||||
|
zval* elements;
|
||||||
|
ZEND_PARSE_PARAMETERS_START(1, 1)
|
||||||
|
Z_PARAM_ZVAL(elements)
|
||||||
|
ZEND_PARSE_PARAMETERS_END();
|
||||||
|
ELEMENTS_VALIDATE(elements, ERR_BAD_ARGUMENT_TYPE, return);
|
||||||
|
zend_array* current = COLLECTION_FETCH_CURRENT();
|
||||||
|
SEPARATE_CURRENT_COLLECTION(current);
|
||||||
|
ZEND_HASH_FOREACH_BUCKET(elements_arr, Bucket* bucket)
|
||||||
|
Z_TRY_ADDREF(bucket->val);
|
||||||
|
if (bucket->key)
|
||||||
|
zend_hash_update(current, bucket->key, &bucket->val);
|
||||||
|
else if (HT_IS_PACKED(elements_arr))
|
||||||
|
zend_hash_next_index_insert(current, &bucket->val);
|
||||||
|
else
|
||||||
|
zend_hash_index_update(current, bucket->h, &bucket->val);
|
||||||
|
ZEND_HASH_FOREACH_END();
|
||||||
}
|
}
|
||||||
|
|
||||||
PHP_METHOD(Collection, reduce)
|
PHP_METHOD(Collection, reduce)
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
--TEST--
|
||||||
|
Test Collection::putAll().
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
$array = ['a' => 'foo', 'b' => 'bar'];
|
||||||
|
$array1 = ['a' => 'b', 'c' => 'd', 'e' => 'f'];
|
||||||
|
$collection = Collection::init($array);
|
||||||
|
$collection->putAll($array1);
|
||||||
|
if ($collection->toArray() != array_merge($array, $array1))
|
||||||
|
echo 'Collection::putAll() failed.', PHP_EOL;
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
Reference in New Issue