|
1 | 1 | function ($base) { |
2 | 2 | $arrayPrototype = function ($base, $key) { |
3 | 3 | if ($key === 'forEach') { |
4 | | - return return function ($callback, $userData = null) use (&$base) { |
| 4 | + return function ($callback, $userData = null) use (&$base) { |
5 | 5 | return array_walk($base, $callback, $userData); |
6 | 6 | }; |
7 | 7 | } |
8 | 8 | if ($key === 'map') { |
9 | | - return return function ($callback) use (&$base) { |
| 9 | + return function ($callback) use (&$base) { |
10 | 10 | return array_map($callback, $base); |
11 | 11 | }; |
12 | 12 | } |
13 | 13 | if ($key === 'filter') { |
14 | | - return return function ($callback, $flag = 0) use ($base) { |
| 14 | + return function ($callback, $flag = 0) use ($base) { |
15 | 15 | return array_filter($base, $callback, $flag); |
16 | 16 | }; |
17 | 17 | } |
18 | 18 | if ($key === 'pop') { |
19 | | - return return function () use (&$base) { |
| 19 | + return function () use (&$base) { |
20 | 20 | return array_pop($base); |
21 | 21 | }; |
22 | 22 | } |
23 | 23 | if ($key === 'shift') { |
24 | | - return return function () use (&$base) { |
| 24 | + return function () use (&$base) { |
25 | 25 | return array_shift($base); |
26 | 26 | }; |
27 | 27 | } |
28 | 28 | if ($key === 'push') { |
29 | | - return return function ($item) use (&$base) { |
| 29 | + return function ($item) use (&$base) { |
30 | 30 | return array_push($base, $item); |
31 | 31 | }; |
32 | 32 | } |
33 | 33 | if ($key === 'unshift') { |
34 | | - return return function ($item) use (&$base) { |
| 34 | + return function ($item) use (&$base) { |
35 | 35 | return array_unshift($base, $item); |
36 | 36 | }; |
37 | 37 | } |
38 | 38 | if ($key === 'indexOf') { |
39 | | - return return function ($item) use (&$base) { |
| 39 | + return function ($item) use (&$base) { |
40 | 40 | $search = array_search($base, $item); |
41 | 41 |
|
42 | 42 | return $search === false ? -1 : $search; |
43 | 43 | }; |
44 | 44 | } |
45 | 45 | if ($key === 'slice') { |
46 | | - return return function ($offset, $length = null, $preserveKeys = false) use (&$base) { |
| 46 | + return function ($offset, $length = null, $preserveKeys = false) use (&$base) { |
47 | 47 | return array_slice($base, $offset, $length, $preserveKeys); |
48 | 48 | }; |
49 | 49 | } |
50 | 50 | if ($key === 'splice') { |
51 | | - return return function ($offset, $length = null, $replacements = array()) use (&$base) { |
| 51 | + return function ($offset, $length = null, $replacements = array()) use (&$base) { |
52 | 52 | return array_splice($base, $offset, $length, $replacements); |
53 | 53 | }; |
54 | 54 | } |
55 | 55 | if ($key === 'reverse') { |
56 | | - return return function () use (&$base) { |
| 56 | + return function () use (&$base) { |
57 | 57 | return array_reverse($base); |
58 | 58 | }; |
59 | 59 | } |
60 | 60 | if ($key === 'reduce') { |
61 | | - return return function ($callback, $initial = null) use (&$base) { |
| 61 | + return function ($callback, $initial = null) use (&$base) { |
62 | 62 | return array_reduce($base, $callback, $initial); |
63 | 63 | }; |
64 | 64 | } |
65 | 65 | if ($key === 'join') { |
66 | | - return return function ($glue) use (&$base) { |
| 66 | + return function ($glue) use (&$base) { |
67 | 67 | return implode($glue, $base); |
68 | 68 | }; |
69 | 69 | } |
70 | 70 | if ($key === 'sort') { |
71 | | - return return function ($callback = null) use (&$base) { |
| 71 | + return function ($callback = null) use (&$base) { |
72 | 72 | return $callback ? usort($base, $callback) : sort($base); |
73 | 73 | }; |
74 | 74 | } |
75 | 75 |
|
76 | 76 | return null; |
77 | 77 | }; |
78 | | - $getFromArray = function ($base, $key) { |
| 78 | + $getFromArray = function ($base, $key) use ($arrayPrototype) { |
79 | 79 | return isset($base[$key]) |
80 | 80 | ? $base[$key] |
81 | 81 | : $arrayPrototype($base, $key); |
|
0 commit comments