Skip to content

Commit d0094b4

Browse files
authored
avoid array_find_key (#38)
1 parent a620627 commit d0094b4

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/helpers.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,13 @@ function array_first($array, ?callable $callback = null, $default = null)
9898
return value($default);
9999
}
100100

101-
$key = array_find_key($array, $callback);
101+
foreach ($array as $key => $value) {
102+
if ($callback($value, $key)) {
103+
return $value;
104+
}
105+
}
102106

103-
return $key !== null ? $array[$key] : value($default);
107+
return value($default);
104108
}
105109
}
106110

0 commit comments

Comments
 (0)