Added DataObjectSet::find(), for using a DOS a bit like a PHP map

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@40910 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2007-08-27 05:09:13 +00:00
parent 0606da72cd
commit 8bcff1f1d6

View File

@ -636,6 +636,17 @@ class DataObjectSet extends ViewableData implements Iterator {
} }
return $map; return $map;
} }
/**
* Find an item in this list where the field $key is equal to $value
* Eg: $doSet->find('ID', 4);
* @return ViewableData The first matching item.
*/
public function find($key, $value) {
foreach($this->items as $item) {
if($item->$key == $value) return $item;
}
}
/** /**
* Return a column of the given field * Return a column of the given field