public function ArrayCollection::partition in Plug 7
Partitions this collection in two collections according to a predicate. Keys are preserved in the resulting collections.
Parameters
Closure $p The predicate on which to partition.:
Return value
array An array with two elements. The first element contains the collection of elements where the predicate returned TRUE, the second element contains the collection of elements where the predicate returned FALSE.
Overrides Collection::partition
File
- lib/
doctrine/ collections/ lib/ Doctrine/ Common/ Collections/ ArrayCollection.php, line 315
Class
- ArrayCollection
- An ArrayCollection is a Collection implementation that wraps a regular PHP array.
Namespace
Doctrine\Common\CollectionsCode
public function partition(Closure $p) {
$matches = $noMatches = array();
foreach ($this->elements as $key => $element) {
if ($p($key, $element)) {
$matches[$key] = $element;
}
else {
$noMatches[$key] = $element;
}
}
return array(
new static($matches),
new static($noMatches),
);
}