function NestedArrayTest::testMergeExplicitKeys
Same name and namespace in other branches
- 8.9.x core/tests/Drupal/Tests/Component/Utility/NestedArrayTest.php \Drupal\Tests\Component\Utility\NestedArrayTest::testMergeExplicitKeys()
- 10 core/tests/Drupal/Tests/Component/Utility/NestedArrayTest.php \Drupal\Tests\Component\Utility\NestedArrayTest::testMergeExplicitKeys()
- 11.x core/tests/Drupal/Tests/Component/Utility/NestedArrayTest.php \Drupal\Tests\Component\Utility\NestedArrayTest::testMergeExplicitKeys()
Tests that even with explicit keys, values are appended, not merged.
@covers ::mergeDeepArray
File
-
core/
tests/ Drupal/ Tests/ Component/ Utility/ NestedArrayTest.php, line 194
Class
- NestedArrayTest
- @coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Component%21Utility%21NestedArray.php/class/NestedArray/9" title="Provides helpers to perform operations on nested arrays and array keys of variable depth." class="local">\Drupal\Component\Utility\NestedArray</a> @group Utility
Namespace
Drupal\Tests\Component\UtilityCode
public function testMergeExplicitKeys() {
$a = [
'subkey' => [
0 => 'A',
1 => 'B',
],
];
$b = [
'subkey' => [
0 => 'C',
1 => 'D',
],
];
// Drupal core behavior.
$expected = [
'subkey' => [
0 => 'A',
1 => 'B',
2 => 'C',
3 => 'D',
],
];
$actual = NestedArray::mergeDeepArray([
$a,
$b,
]);
$this->assertSame($expected, $actual, 'drupal_array_merge_deep() creates new numeric keys in the explicit sequence.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.