Skip to content

Commit d5c00d9

Browse files
Helpers str_limit, array_last and array_where added.
1 parent 0bead22 commit d5c00d9

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

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

146176
### head
147177

@@ -212,6 +242,18 @@ Convert the given string to `snake_case`.
212242
$snake = snake_case('fooBar');
213243

214244
// foo_bar
245+
246+
### str_limit
247+
248+
Limit the number of characters in a string.
249+
250+
str_limit($value, $limit = 100, $end = '...')
251+
252+
Example:
253+
254+
$value = str_limit('The PHP framework for web artisans.', 7);
255+
256+
// The PHP...
215257

216258
### starts_with
217259

0 commit comments

Comments
 (0)