Skip to content

Commit d18eea1

Browse files
committed
Merge pull request laravel#582 from KennedyTedesco/patch-1
Helpers str_limit, array_last and array_where added.
2 parents a16e7c3 + d5c00d9 commit d18eea1

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

helpers.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,23 @@ The `array_first` method returns the first element of an array passing a given t
6868
A default value may also be passed as the third parameter:
6969

7070
$value = array_first($array, $callback, $default);
71+
72+
### array_last
73+
74+
The `array_last` method returns the last element of an array passing a given truth test.
75+
76+
$array = array(350, 400, 500, 300, 200, 100);
77+
78+
$value = array_last($array, function($key, $value)
79+
{
80+
return $value > 350;
81+
});
82+
83+
// 500
84+
85+
A default value may also be passed as the third parameter:
86+
87+
$value = array_last($array, $callback, $default);
7188

7289
### array_flatten
7390

@@ -144,6 +161,19 @@ The `array_sort` method sorts the array by the results of the given Closure.
144161
{
145162
return $value['name'];
146163
}));
164+
165+
### array_where
166+
167+
Filter the array using the given Closure.
168+
169+
$array = array(100, '200', 300, '400', 500);
170+
171+
$array = array_where($array, function($key, $value)
172+
{
173+
return is_string($value);
174+
});
175+
176+
// Array ( [1] => 200 [3] => 400 )
147177

148178
### head
149179

@@ -216,6 +246,18 @@ Convert the given string to `snake_case`.
216246
$snake = snake_case('fooBar');
217247

218248
// foo_bar
249+
250+
### str_limit
251+
252+
Limit the number of characters in a string.
253+
254+
str_limit($value, $limit = 100, $end = '...')
255+
256+
Example:
257+
258+
$value = str_limit('The PHP framework for web artisans.', 7);
259+
260+
// The PHP...
219261

220262
### starts_with
221263

0 commit comments

Comments
 (0)