-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBox.php
More file actions
32 lines (29 loc) · 724 Bytes
/
Box.php
File metadata and controls
32 lines (29 loc) · 724 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
namespace App;
class Box
{
public function box(array $box): string
{
foreach ($box as $item) {
if ($item !== 'key') {
if (is_array($item)) {
return $this->box($item);
}
} else {
return array_shift($box);
}
}
}
public function boxIter(array $box): string
{
$iter = array_reduce($box, function ($acc, $item) {
if ($item === 'key' && !is_array($item)) {
$acc .= $item;
} elseif (is_array($item)) {
$acc .= $this->boxIter($item);
}
return $acc;
}, '');
return $iter;
}
}