Arr::setNestedElement(array|ArrayAccess $array, mixed $keys, mixed $value): array|ArrayAccess
set(array|ArrayAccess $array, $keys, $value) -> setNestedElement(array|ArrayAccess $array, $keys, $value)
Set array element specified by keys to the desired value (create missing keys if necessary).
$array = ['key1' => ['key2' => ['key3' => ['test']]]];
Arr::setNestedElement([], 'key1.key2.key3', ['test']) -> $array
$array = Arr::setNestedElement($array, 'key1.key2.key4', 'test2');
$array['key1']['key2']['key4'] -> 'test2'
// Create nested array element using automatic index
Arr::setNestedElement($array, 'foo.[].foo', 'bar') ->
[
'foo' => [
[
'foo' => 'bar',
],
],
]
Arr::setNestedElement([], '[].[].[]', 'test') -> [ [ [ 'test' ] ] ]