Skip to content

Commit 1646c61

Browse files
committed
Update README and change signature for Arr::flatten
1 parent b52b87a commit 1646c61

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,4 +242,14 @@ Validator::isstring('Hello world!');
242242

243243
// This is valid because 'String' starts with uppercased letter.
244244
Validator::isString('Hello world!');
245-
```
245+
```
246+
247+
### `\Noname\Common\Arr`
248+
249+
A helper library for working with arrays.
250+
251+
#### Arr Methods
252+
253+
##### `Arr::flatten(array $array, string $separator = '.', string $prepend = '') : array`
254+
255+
Flatten an associative array using a custom separator.

src/Arr.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ class Arr
1414
* By default this method will use a dot (.) as the separator.
1515
*
1616
* @param array $array
17-
* @param string $prepend
1817
* @param string $separator
18+
* @param string $prepend
1919
* @return array
2020
*/
21-
public static function flatten(array $array, string $prepend = '', string $separator = '.'): array
21+
public static function flatten(array $array, string $separator = '.', string $prepend = ''): array
2222
{
2323
$flatArray = [];
2424

2525
foreach ($array as $key => $value) {
2626
if (is_array($value) && !empty($value)) {
27-
$flatArray += self::flatten($value, $prepend . $key . $separator, $separator);
27+
$flatArray += self::flatten($value, $separator, $prepend . $key . $separator);
2828
} else {
2929
$flatArray[$prepend . $key] = $value;
3030
}

0 commit comments

Comments
 (0)