refactoring router route delegation.

This commit is contained in:
Taylor Otwell
2011-09-13 21:47:25 -05:00
parent cd609d9b39
commit bae9553aac
3 changed files with 61 additions and 49 deletions

View File

@@ -77,4 +77,24 @@ class Arr {
$array[array_shift($keys)] = $value;
}
/**
* Return the first element in an array which passes a given truth test.
*
* <code>
* // Get the first element in an array that is less than 2
* $value = Arr::first(array(4, 3, 2, 1), function($key, $value) {return $value < 2;});
* </code>
*
* @param array $array
* @param Closure $callback
* @return mixed
*/
public static function first($array, $callback)
{
foreach ($array as $key => $value)
{
if (call_user_func($callback, $key, $value)) return $value;
}
}
}