Skip to content

Commit 2db3b7f

Browse files
committed
feat: add searchWithKey utility
1 parent 3bbe0d0 commit 2db3b7f

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/Traits/CollectionUtilities.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,16 @@ public function reverse(bool $preserveKeys = false): self
508508
return $inst;
509509
}
510510

511+
512+
public function searchWithKey(string $findWithKey, string $matchTo): self
513+
{
514+
$inst = clone $this;
515+
$inst->raw = array_values(array_filter($inst->raw, fn($p) => $p[$findWithKey] === $matchTo))[0] ?? [];
516+
return $inst;
517+
}
518+
519+
520+
511521
/**
512522
* Searches the array for a given value and returns the first corresponding 'key' if
513523
* successful to a collection

0 commit comments

Comments
 (0)