createMulti

Definition

1
Arr::createMulti(array $keys, ?array $values = null): array
Copied!

Description

Create multidimensional array using either first param as config of keys and values or separate keys and values arrays

Examples

1
Arr::createMulti([
2
'test.[]' => '123',
3
'test.test2.test3' => 'abc',
4
'test.test2.[]' => 567,
5
'test.[].1' => 'def',
6
]) ->
7
[
8
'test' => [
9
'123',
10
'test2' => [
11
'test3' => 'abc',
12
567
13
],
14
[
15
1 => 'def'
16
],
17
]
18
]
19
20
Arr::createMulti([
21
['test', '[]'],
22
['test', 'test2', 'test3'],
23
['test', 'test2', '[]'],
24
['test', '[]', 1],
25
], [
26
'123',
27
'abc',
28
567,
29
'def',
30
]) ->
31
[
32
'test' => [
33
'123',
34
'test2' => [
35
'test3' => 'abc',
36
567
37
],
38
[
39
1 => 'def'
40
],
41
]
42
]
43
44
// In case of empty keys argument simply return new empty array
45
Arr::createMulti([]) -> []
Copied!
Last modified 2yr ago
Copy link