Skip to content

Commit 0543d75

Browse files
author
Alaa Sarhan
committed
Added documentation
1 parent a4777c6 commit 0543d75

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sarhan/php-flatten",
3-
"description": "Flattens multidimensional arrays into one dimensional array.",
3+
"description": "Flattens multidimensional arrays, traversables and vars into one dimensional array.",
44
"type": "library",
55
"keywords": ["array", "flatten", "arrays"],
66
"homepage": "https://github.com/AlaaSarhan/php-flatten",

src/Flatten.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,21 @@
77
*/
88
class Flatten
99
{
10+
/**
11+
* Flattens a variable, possible traversable, into a one-dimensional array, recursively.
12+
*
13+
* Each key in the returned one-dimensional array is the join of all keys leading to each value, in all dimensions,
14+
* separated by a given separator. That is a fully-qualified key.
15+
*
16+
* Non-traversable values will be returned as-is, after being put into the final array with the fully-qualified key.
17+
*
18+
* An initial prefix can be optionally to namespace all returned keys using that prefix.
19+
*
20+
* @param mixed $var
21+
* @param string $separator
22+
* @param string $prefix
23+
* @return array One-dimensional array containing all values from all possible traversable dimensions in given input.
24+
*/
1025
public static function flatten($var, $separator = '.', $prefix = '')
1126
{
1227
$flattened = [];

0 commit comments

Comments
 (0)