You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can use the `typerocket_view_document_title` to set a view's document title text. This can be helpful when an SEO plugin overrides the document title text, and you want to set the view's title.
Copy file name to clipboardExpand all lines: v5/utilities.md
+176-8Lines changed: 176 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,6 +20,25 @@ Arr::divide($array);
20
20
// [ ['one', 'two'],[1,2] ]
21
21
```
22
22
23
+
## Arr:exists
24
+
25
+
The `Arr::exists()` method check if a key exists for the given `array` or `ArrayAccess` object:
26
+
27
+
```php
28
+
use \TypeRocket\Utility\Arr;
29
+
30
+
$array = ['one' => 1];
31
+
32
+
Arr::exists($array, 'one');
33
+
// true
34
+
35
+
$array = new \ArrayObject();
36
+
$array['one'] = 1;
37
+
38
+
Arr::exists($array, 'one');
39
+
// true
40
+
```
41
+
23
42
### Arr::filterNull
24
43
25
44
The `Arr::filterNull()` method removes all `null` values from the given array:
@@ -33,6 +52,45 @@ Arr::filterNull($array);
33
52
// [0 => 0]
34
53
```
35
54
55
+
### Arr::first
56
+
57
+
The `Arr::first()` method returns the first element of an array:
58
+
59
+
```php
60
+
use \TypeRocket\Utility\Arr;
61
+
62
+
$array = [1, 2, 3];
63
+
64
+
Arr::first($array);
65
+
// 1
66
+
```
67
+
68
+
As the second parameter a callback may be passed to the method. When the callback returns `true` the first element passing a given truth test is returned:
69
+
70
+
```php
71
+
use \TypeRocket\Utility\Arr;
72
+
$array = [1, 2, 3];
73
+
74
+
Arr::first($array, function ($value, $key) {
75
+
return $value === 2;
76
+
});
77
+
// 2
78
+
```
79
+
80
+
A default value may also be passed as the third parameter to the method. This value will be returned if no value passes the truth test:
81
+
82
+
```php
83
+
use \TypeRocket\Utility\Arr;
84
+
85
+
$array = [1, 2, 3];
86
+
$default = 4;
87
+
88
+
Arr::first($array, function ($value, $key) {
89
+
return $value > 3;
90
+
}, $default);
91
+
// 4
92
+
```
93
+
36
94
### Arr::format
37
95
38
96
The `Arr::format()` method applies a callback to an arrays a values using dot notation. The returned value is the endpoint of the dot notation lookup. The array is mutated by reference.
The `Arr::last()` method returns the first element of an array:
280
+
281
+
```php
282
+
use \TypeRocket\Utility\Arr;
283
+
284
+
$array = [1, 2, 3];
285
+
286
+
Arr::last($array);
287
+
// 3
288
+
```
289
+
290
+
As the second parameter a callback may be passed to the method. When the callback returns `true` the last element passing a given truth test is returned:
291
+
292
+
```php
293
+
use \TypeRocket\Utility\Arr;
294
+
$array = [1, 2, 3];
295
+
296
+
Arr::last($array, function ($value, $key) {
297
+
return $value === 2;
298
+
});
299
+
// 2
300
+
```
301
+
302
+
A default value may also be passed as the third parameter to the method. This value will be returned if no value passes the truth test:
303
+
304
+
```php
305
+
use \TypeRocket\Utility\Arr;
306
+
307
+
$array = [1, 2, 3];
308
+
$default = 4;
309
+
310
+
Arr::last($array, function ($value, $key) {
311
+
return $value > 3;
312
+
}, $default);
313
+
// 4
314
+
```
315
+
208
316
### Arr::meld
209
317
210
318
The `Arr::meld()` method reduces a deeply nested array into a dot notation keyed flat array:
Use the method `Str::uppercaseWords()`to apply`MB_CASE_TITLE` to a string.
766
+
The `Str::uppercaseWords()`method applies`MB_CASE_TITLE` to a string:
642
767
643
768
```php
644
769
use \TypeRocket\Utility\Str;
@@ -873,6 +998,49 @@ Data::isJson('""');
873
998
// false
874
999
```
875
1000
1001
+
### Data::map
1002
+
1003
+
The `Data::map()` method maps a function to a value, or when an array or an object all iterable values:
1004
+
1005
+
```php
1006
+
use TypeRocket\Utility\Data;
1007
+
1008
+
$object = new \stdClass();
1009
+
$object->one = 1;
1010
+
1011
+
Data::map(function($value) {
1012
+
return $value * 4;
1013
+
}, $object);
1014
+
// $object->one = 4
1015
+
1016
+
$array = ['one' => 1];
1017
+
1018
+
Data::map(function($value) {
1019
+
return $value * 4;
1020
+
}, $array);
1021
+
// ['one' => 4]
1022
+
1023
+
$int = 1;
1024
+
1025
+
Data::map(function($value) {
1026
+
return $value * 4;
1027
+
}, $int);
1028
+
// 4
1029
+
```
1030
+
1031
+
### Data::mapDeep
1032
+
1033
+
The `Data::mapDeep()` method maps a function to all non-iterable elements of an array or an object. This is similar to `array_walk_recursive()` but acts upon objects too:
1034
+
1035
+
```php
1036
+
use TypeRocket\Utility\Data;
1037
+
1038
+
Data::mapDeep(function($value) {
1039
+
return $value * 4;
1040
+
}, [[2],[2], 2]);
1041
+
// [ [8], [8], 8 ]
1042
+
```
1043
+
876
1044
### Data::nil
877
1045
878
1046
The `Data::nil()` method allows for chaining a number of property lookups without throwing an error. It does not provide access to object functions.
0 commit comments