@@ -83,7 +83,21 @@ function array_except($array, $keys)
83
83
*/
84
84
function array_first ($ array , ?callable $ callback = null , $ default = null )
85
85
{
86
- return Arr::first ($ array , $ callback , $ default );
86
+ if (is_null ($ callback )) {
87
+ if (empty ($ array )) {
88
+ return value ($ default );
89
+ }
90
+
91
+ foreach ($ array as $ item ) {
92
+ return $ item ;
93
+ }
94
+
95
+ return value ($ default );
96
+ }
97
+
98
+ $ key = array_find_key ($ array , $ callback );
99
+
100
+ return $ key !== null ? $ array [$ key ] : value ($ default );
87
101
}
88
102
}
89
103
@@ -155,7 +169,11 @@ function array_has($array, $keys)
155
169
*/
156
170
function array_last ($ array , ?callable $ callback = null , $ default = null )
157
171
{
158
- return Arr::last ($ array , $ callback , $ default );
172
+ if (is_null ($ callback )) {
173
+ return empty ($ array ) ? value ($ default ) : end ($ array );
174
+ }
175
+
176
+ return Arr::first (array_reverse ($ array , true ), $ callback , $ default );
159
177
}
160
178
}
161
179
@@ -409,7 +427,21 @@ function str_before($subject, $search)
409
427
*/
410
428
function str_contains ($ haystack , $ needles )
411
429
{
412
- return Str::contains ($ haystack , $ needles );
430
+ if (is_null ($ haystack )) {
431
+ return false ;
432
+ }
433
+
434
+ if (! is_iterable ($ needles )) {
435
+ $ needles = (array ) $ needles ;
436
+ }
437
+
438
+ foreach ($ needles as $ needle ) {
439
+ if ($ needle !== '' && strpos ($ haystack , $ needle ) !== false ) {
440
+ return true ;
441
+ }
442
+ }
443
+
444
+ return false ;
413
445
}
414
446
}
415
447
0 commit comments