Permalink
Browse files

Add helper method to retrieve the last item from an array (the opposi…

…te to array_first() in a sense).

Signed-off-by: Ben Corlett <bencorlett@me.com>
  • Loading branch information...
bencorlett committed Dec 4, 2013
1 parent e8d523c commit 88421ddc6b2313ec16cd65b66a03ee8258e02702
Showing with 16 additions and 0 deletions.
  1. +16 −0 src/Illuminate/Support/helpers.php
@@ -198,6 +198,22 @@ function array_first($array, $callback, $default = null)
}
}
if ( ! function_exists('array_last'))
{
/**
* Return the last element in an array passing a given truth test.
*
* @param array $array
* @param Closure $callback
* @param mixed $default
* @return mixed
*/
function array_last($array, $callback, $default = null)
{
return array_first(array_reverse($array), $callback, $default);
}
}
if ( ! function_exists('array_flatten'))
{
/**

0 comments on commit 88421dd

Please sign in to comment.