| @@ 38-48 (lines=11) @@ | ||
| 35 | * |
|
| 36 | * @return array |
|
| 37 | */ |
|
| 38 | public static function build($array, Closure $callback) |
|
| 39 | { |
|
| 40 | $results = []; |
|
| 41 | ||
| 42 | foreach ($array as $key => $value) { |
|
| 43 | list($innerKey, $innerValue) = call_user_func($callback, $key, $value); |
|
| 44 | $results[$innerKey] = $innerValue; |
|
| 45 | } |
|
| 46 | ||
| 47 | return $results; |
|
| 48 | } |
|
| 49 | ||
| 50 | /** |
|
| 51 | * Divide an array into two arrays. One with keys and the other with values. |
|
| @@ 352-363 (lines=12) @@ | ||
| 349 | * |
|
| 350 | * @return array |
|
| 351 | */ |
|
| 352 | public static function where($array, Closure $callback) |
|
| 353 | { |
|
| 354 | $filtered = []; |
|
| 355 | ||
| 356 | foreach ($array as $key => $value) { |
|
| 357 | if (call_user_func($callback, $key, $value)) { |
|
| 358 | $filtered[$key] = $value; |
|
| 359 | } |
|
| 360 | } |
|
| 361 | ||
| 362 | return $filtered; |
|
| 363 | } |
|
| 364 | } |
|
| 365 | ||