Flatten array
This commit is contained in:
parent
3171da146f
commit
fee5c1afe4
4 changed files with 52 additions and 0 deletions
31
tests/FlattenArrayTest.php
Normal file
31
tests/FlattenArrayTest.php
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use function App\flattenArray;
|
||||
|
||||
it('flattens an array', function (
|
||||
array $input,
|
||||
array $expected
|
||||
): void {
|
||||
$result = flattenArray($input);
|
||||
|
||||
assertSame($expected, $result);
|
||||
})->with([
|
||||
[
|
||||
'input' => [1, 2, 3],
|
||||
'expected' => [1, 2, 3],
|
||||
],
|
||||
[
|
||||
'input' => [1, [2, 3, null, 4], [null], 5],
|
||||
'expected' => [1, 2, 3, 4, 5],
|
||||
],
|
||||
[
|
||||
'input' => [1, [2, [[3]], [4, [[5]]], 6, 7], 8],
|
||||
'expected' => [1, 2, 3, 4, 5, 6, 7, 8],
|
||||
],
|
||||
[
|
||||
'input' => [null, [[[null]]], null, null, [[null, null], null], null],
|
||||
'expected' => [],
|
||||
]
|
||||
]);
|
Loading…
Add table
Add a link
Reference in a new issue