Skip to content

Commit

Permalink
added RowCollection::find()
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed Dec 8, 2015
1 parent d7c3e2a commit 8885dc7
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/RowCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ public function add($rows)
* @param mixed $value The value to filter
* @param bool $strict Strict mode
*
* @return RowInterface The rows found
* @return RowCollection
*/
public function filter($name, $value, $strict = true)
{
Expand All @@ -340,6 +340,24 @@ public function filter($name, $value, $strict = true)
return $this->entity->createCollection($rows);
}

/**
* Find a row by a value.
*
* @param string $name The value name
* @param mixed $value The value to filter
* @param bool $strict Strict mode
*
* @return Row|null The rows found
*/
public function find($name, $value, $strict = true)
{
foreach ($this->rows as $row) {
if (($row->$name === $value) || (!$strict && $row->$name == $value) || (is_array($value) && in_array($row->$name, $value, $strict))) {
return $row;
}
}
}

/**
* Distribute a rowcollection througth all rows.
*
Expand Down

0 comments on commit 8885dc7

Please sign in to comment.