diff --git a/system/Validation/DotArrayFilter.php b/system/Validation/DotArrayFilter.php index 4f696886451d..1ba9b92fa710 100644 --- a/system/Validation/DotArrayFilter.php +++ b/system/Validation/DotArrayFilter.php @@ -44,7 +44,7 @@ public static function run(array $indexes, array $array): array $segments ); - $result = array_merge_recursive($result, self::filter($segments, $array)); + $result = array_replace_recursive($result, self::filter($segments, $array)); } return $result; diff --git a/tests/system/Validation/DotArrayFilterTest.php b/tests/system/Validation/DotArrayFilterTest.php index 6d3b380f517a..c5d5b8310841 100644 --- a/tests/system/Validation/DotArrayFilterTest.php +++ b/tests/system/Validation/DotArrayFilterTest.php @@ -180,4 +180,19 @@ public function testRunNestedArray() ]; $this->assertSame($expected, $result); } + + public function testRunReturnOrderedIndices() + { + $data = [ + 'foo' => [ + 2 => 'bar', + 0 => 'baz', + 1 => 'biz', + ], + ]; + + $result = DotArrayFilter::run(['foo.2', 'foo.0', 'foo.1'], $data); + + $this->assertSame($data, $result); + } }