diff --git a/README.md b/README.md index 6b7fec4..587e8b3 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,8 @@ Plain numeric arrays are handled best via the methods in A, while associative ar - **of** - concatenates every argument into an array as is + _See also: A::concat()_ + ```php $items = A::of(1, 2, [3]); // [1, 2, [3]] ``` @@ -87,7 +89,17 @@ Plain numeric arrays are handled best via the methods in A, while associative ar - **length** - - **isEmpty** - - **isNotEmpty** - -- **ensureArray** - wraps parameter into an array if it's anything else, than a numeric array + +- **ensureArray** - wraps parameter into an array if it's not a numeric array + + ```php + A::ensureArray(123); // [123] + ``` + + ```php + A::ensureArray([4, 5, 6]); // [4, 5, 6] + ``` + - **append** - - **prepend** - - **pluck** - @@ -272,11 +284,14 @@ Plain numeric arrays are handled best via the methods in A, while associative ar - **includes** - - **contains** - - - **slice** - - **join** - + - **pickRandom** - selects a random item from the given array -- **concat** - concatenates every argument into an array. if any of the arguments are arrays, then those will get unnested + +- **concat** - concatenates every argument into an array. if any of the arguments are numeric arrays, then those will get unnested + + _See also: A::of()_ ```php A::concat([1, 2], 3, [4, 5]); // [1, 2, 3, 4, 5] diff --git a/src/A.php b/src/A.php index bdff5fa..e34809a 100644 --- a/src/A.php +++ b/src/A.php @@ -106,15 +106,15 @@ public static function ensureArray($data): array } // A::append([4, 5, 6], [1, 2]) -> [1, 2, 4, 5, 6] - public static function append(array $arr, array $data): array + public static function append($value, array $data): array { - return array_merge($data, self::ensureArray($arr)); + return self::concat($data, $value); } // A::prepend([4, 5, 6], [1, 2]) -> [4, 5, 6, 1, 2] - public static function prepend(array $arr, array $data): array + public static function prepend($value, array $data): array { - return array_merge(self::ensureArray($arr), $data); + return self::concat($value, $data); } // A::pluck('color', [['color' => 'red', ...], ['color' => 'green', ...]]) -> ['red', 'green']