| @@ 57-67 (lines=11) @@ | ||
| 54 | * |
|
| 55 | * @return array |
|
| 56 | */ |
|
| 57 | public static function build($array, Closure $callback) |
|
| 58 | { |
|
| 59 | $results = []; |
|
| 60 | ||
| 61 | foreach ($array as $key => $value) { |
|
| 62 | list($innerKey, $innerValue) = call_user_func($callback, $key, $value); |
|
| 63 | $results[$innerKey] = $innerValue; |
|
| 64 | } |
|
| 65 | ||
| 66 | return $results; |
|
| 67 | } |
|
| 68 | ||
| 69 | /** |
|
| 70 | * Divide an array into two arrays. One with keys and the other with values. |
|
| @@ 371-382 (lines=12) @@ | ||
| 368 | * |
|
| 369 | * @return array |
|
| 370 | */ |
|
| 371 | public static function where($array, Closure $callback) |
|
| 372 | { |
|
| 373 | $filtered = []; |
|
| 374 | ||
| 375 | foreach ($array as $key => $value) { |
|
| 376 | if (call_user_func($callback, $key, $value)) { |
|
| 377 | $filtered[$key] = $value; |
|
| 378 | } |
|
| 379 | } |
|
| 380 | ||
| 381 | return $filtered; |
|
| 382 | } |
|
| 383 | } |
|
| 384 | ||