Skip to content

Commit

Permalink
Merge pull request #36 from transprime-research/feat-add-array-search…
Browse files Browse the repository at this point in the history
…-with-closure-search-using-key-and-value

feat: Fix default value missing when keys are empty
  • Loading branch information
omitobi authored Apr 30, 2024
2 parents 903dfc5 + d3d0ac9 commit e66cea4
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Traits/ArrayPrefix.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ public function walkRecursive(callable $callable, $arg = null)
public function search($needle, bool $strict = true, $default = null)
{
if ($needle instanceof \Closure) {
return $this
$result = $this
->copy()
->filter(fn($value, $key) => $needle($value, $key))
->keys(false)
->when($this->getWorkableItem(), new self([$default]))
->offsetGet(0);
->keys(false);

return $result->empty() ? $default : $result->offsetGet(0);
}


Expand Down

0 comments on commit e66cea4

Please sign in to comment.