@@ -165,6 +165,7 @@ will return:
165165<a href =" #first " >first</a >
166166<a href =" #firstkey " >firstKey</a >
167167<a href =" #flat " >flat</a >
168+ <a href =" #flatten " >flatten</a >
168169<a href =" #flip " >flip</a >
169170<a href =" #float " >float</a >
170171<a href =" #from " >from</a >
@@ -249,6 +250,7 @@ will return:
249250<a href =" #shuffled " >shuffled</a >
250251<a href =" #skip " >skip</a >
251252<a href =" #slice " >slice</a >
253+ <a href =" #sliding " >sliding</a >
252254<a href =" #some " >some</a >
253255<a href =" #sort " >sort</a >
254256<a href =" #sorted " >sorted</a >
@@ -286,6 +288,7 @@ will return:
286288<a href =" #uasorted " >uasorted</a >
287289<a href =" #uksort " >uksort</a >
288290<a href =" #uksorted " >uksorted</a >
291+ <a href =" #unflatten " >unflatten</a >
289292<a href =" #union " >union</a >
290293<a href =" #unique " >unique</a >
291294<a href =" #unshift " >unshift</a >
@@ -472,6 +475,7 @@ will return:
472475* [ collapse()] ( #collapse ) : Collapses multi-dimensional elements overwriting elements
473476* [ combine()] ( #combine ) : Combines the map elements as keys with the given values
474477* [ flat()] ( #flat ) : Flattens multi-dimensional elements without overwriting elements
478+ * [ flatten()] ( #flatten ) : Creates a new map with keys joined recursively
475479* [ flip()] ( #flip ) : Exchanges keys with their values
476480* [ groupBy()] ( #groupby ) : Groups associative array elements or objects
477481* [ join()] ( #join ) : Returns concatenated elements as string with separator
@@ -485,6 +489,7 @@ will return:
485489* [ rekey()] ( #rekey ) : Changes the keys according to the passed function
486490* [ replace()] ( #replace ) : Replaces elements recursively
487491* [ rtrim()] ( #rtrim ) : Removes the passed characters from the right of all strings
492+ * [ sliding()] ( #sliding ) : Returns a new map containing sliding windows of the original map
488493* [ splice()] ( #splice ) : Replaces a slice by new elements
489494* [ strAfter()] ( #strafter ) : Returns the strings after the passed value
490495* [ strBefore()] ( #strbefore ) : Returns the strings before the passed value
@@ -498,6 +503,7 @@ will return:
498503* [ transpose()] ( #transpose ) : Exchanges rows and columns for a two dimensional map
499504* [ traverse()] ( #traverse ) : Traverses trees of nested items passing each item to the callback
500505* [ trim()] ( #trim ) : Removes the passed characters from the left/right of all strings
506+ * [ unflatten()] ( #unflatten ) : Unflattens the key path/value pairs into a multi-dimensional array
501507* [ walk()] ( #walk ) : Applies the given callback to all elements
502508* [ zip()] ( #zip ) : Merges the values of all arrays at the corresponding index
503509
@@ -1652,7 +1658,7 @@ Sets or returns the seperator for paths to values in multi-dimensional arrays or
16521658public static function delimiter( ?string $char = null ) : string
16531659```
16541660
1655- * @param ** string** ` $char ` Separator character, e.g. "." for "key.to.value" instaed of "key/to/value"
1661+ * @param ** string&# 124 ; null ** ` $char ` Separator character, e.g. "." for "key.to.value" instaed of "key/to/value"
16561662* @return ** string** Separator used up to now
16571663
16581664The static method only changes the separator for new maps created afterwards.
@@ -2362,6 +2368,39 @@ Map::from( [[0, 1], Map::from( [[2, 3], 4] )] )->flat();
23622368* [ collapse()] ( #collapse ) - Collapses all sub-array elements recursively to a new map
23632369
23642370
2371+ ### flatten()
2372+
2373+ c.
2374+
2375+ ``` php
2376+ public function flatten( ?int $depth = null ) : self
2377+ ```
2378+
2379+ * @param ** int| ; null** ` $depth ` Number of levels to flatten multi-dimensional arrays or NULL for all
2380+ * @return ** self< ; string,mixed> ; ** New map with keys joined recursively, up to the specified depth
2381+
2382+ To create the original multi-dimensional array again, use the [ unflatten()] ( #unflatten ) method.
2383+
2384+ ** Examples:**
2385+
2386+ ``` php
2387+ Map::from( ['a' => ['b' => ['c' => 1, 'd' => 2]], 'b' => ['e' => 3]] )->flatten();
2388+ // ['a/b/c' => 1, 'a/b/d' => 2, 'b/e' => 3]
2389+
2390+ Map::from( ['a' => ['b' => ['c' => 1, 'd' => 2]], 'b' => ['e' => 3]] )->flatten( 1 );
2391+ // ['a/b' => ['c' => 1, 'd' => 2], 'b/e' => 3]
2392+
2393+ Map::from( ['a' => ['b' => ['c' => 1, 'd' => 2]], 'b' => ['e' => 3]] )->sep( '.' )->flatten();
2394+ // ['a.b.c' => 1, 'a.b.d' => 2, 'b.e' => 3]
2395+ ```
2396+
2397+ ** See also:**
2398+
2399+ * [ flat()] ( #flat ) - Flattens multi-dimensional elements without overwriting elements
2400+ * [ collapse()] ( #collapse ) - Collapses all sub-array elements recursively to a new map
2401+ * [ unflatten()] ( #unflatten ) - Unflattens the key path/value pairs into a multi-dimensional array
2402+
2403+
23652404### flip()
23662405
23672406Exchanges the keys with their values and vice versa.
@@ -3091,12 +3130,12 @@ Map::from( ['foo', 'bar'] )->insertAfter( null, 'baz' );
30913130Inserts the item at the given position in the map.
30923131
30933132``` php
3094- public function insertAt( int $pos, $element , $key = null ) : self
3133+ public function insertAt( int $pos, $value , $key = null ) : self
30953134```
30963135
3097- * @param ** int** ` $pos ` Position the element it should be inserted at
3098- * @param ** mixed** ` $element ` Element to be inserted
3099- * @param ** mixed| ; null** ` $key ` Element key or NULL to assign an integer key automatically
3136+ * @param ** int** ` $pos ` Position the value should be inserted at
3137+ * @param ** mixed** ` $value ` Value to be inserted
3138+ * @param ** mixed| ; null** ` $key ` Value key or NULL to assign an integer key automatically
31003139* @return ** self< ; int| ; string,mixed> ; ** Updated map for fluid interface
31013140
31023141** Examples:**
@@ -5458,6 +5497,36 @@ Map::from( ['a', 'b', 'c', 'd'] )->slice( -2, -1 );
54585497* [ take()] ( #take ) - Returns a new map with the given number of items.
54595498
54605499
5500+ ### sliding()
5501+
5502+ Returns a new map containing sliding windows of the original map.
5503+
5504+ ``` php
5505+ public function sliding( int $size = 2, int $step = 1 ) : self
5506+ ```
5507+
5508+ * @param ** int** $size Size of each window
5509+ * @param ** int** $step Step size to move the window
5510+ * @return ** self< ; int,array< ; int| ; string,mixed> ;> ; ** New map containing arrays for each window
5511+
5512+ ** Examples:**
5513+
5514+ ``` php
5515+ Map::from( [1, 2, 3, 4] )->sliding( 2 );
5516+ // [
5517+ // [0 => 1, 1 => 2],
5518+ // [1 => 2, 2 => 3],
5519+ // [2 => 3, 3 => 4]
5520+ // ]
5521+
5522+ Map::from( [1, 2, 3, 4] )->sliding( 3, 2 );
5523+ // [
5524+ // [0 => 1, 1 => 2, 2 => 3],
5525+ // [2 => 3, 3 => 4, 4 => 5]
5526+ // ]
5527+ ```
5528+
5529+
54615530### some()
54625531
54635532Tests if at least one element passes the test or is part of the map.
@@ -6997,6 +7066,35 @@ Map::from( ['B' => 'a', 'a' => 'b'] )->uksorted( function( $keyA, $keyB ) {
69977066* [ uksort()] ( #uksort ) - Sorts the map elements by their keys using a callback
69987067
69997068
7069+ ### unflatten()
7070+
7071+ Unflattens the key path/value pairs into a multi-dimensional array.
7072+
7073+ ``` php
7074+ public function unflatten() : self
7075+ ```
7076+
7077+ This is the inverse method for [ flatten()] ( #flatten ) .
7078+
7079+ * @return ** self< ; string,mixed> ; ** New map with multi-dimensional arrays
7080+
7081+ ** Examples:**
7082+
7083+ ``` php
7084+ Map::from( ['a/b/c' => 1, 'a/b/d' => 2, 'b/e' => 3] )->unflatten();
7085+ // ['a' => ['b' => ['c' => 1, 'd' => 2]], 'b' => ['e' => 3]]
7086+
7087+ Map::from( ['a.b.c' => 1, 'a.b.d' => 2, 'b.e' => 3] )->sep( '.' )->unflatten();
7088+ // ['a' => ['b' => ['c' => 1, 'd' => 2]], 'b' => ['e' => 3]]
7089+ ```
7090+
7091+ ** See also:**
7092+
7093+ * [ collapse()] ( #collapse ) - Collapses all sub-array elements recursively to a new map
7094+ * [ flat()] ( #flat ) - Flattens multi-dimensional elements without overwriting elements
7095+ * [ flatten()] ( #flatten ) - Creates a new map with keys joined recursively
7096+
7097+
70007098### union()
70017099
70027100Builds a union of the elements and the given elements without returning a new map.
0 commit comments