File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change 3
3
4
4
namespace BrenoRoosevelt ;
5
5
6
+ use RecursiveArrayIterator ;
7
+ use RecursiveIteratorIterator ;
8
+
6
9
/**
7
10
* @param array $items
8
- * @param string|null $separator
11
+ * @param string|null $pathSeparator
9
12
* @return array
10
13
*/
11
- function flatten (array $ items , ?string $ separator = null )
14
+ function flatten (array $ items , ?string $ pathSeparator = null ): array
12
15
{
13
16
$ result = [];
14
- $ iterator = new \ RecursiveIteratorIterator (new \ RecursiveArrayIterator ($ items ));
17
+ $ iterator = new RecursiveIteratorIterator (new RecursiveArrayIterator ($ items ));
15
18
foreach ($ iterator as $ leafValue ) {
16
19
$ keys = [];
17
20
foreach (range (0 , $ iterator ->getDepth ()) as $ depth ) {
18
21
$ keys [] = $ iterator ->getSubIterator ($ depth )->key ();
19
22
}
20
23
21
- if (! empty ($ separator )) {
22
- $ result [join ($ separator , $ keys ) ] = $ leafValue ;
24
+ if (! empty ($ pathSeparator )) {
25
+ $ result [join ($ pathSeparator , $ keys ) ] = $ leafValue ;
23
26
} else {
24
27
$ result [] = $ leafValue ;
25
28
}
You can’t perform that action at this time.
0 commit comments