Skip to content

Commit

Permalink
#3 - Add filter() method to allow filtering the data collection
Browse files Browse the repository at this point in the history
  • Loading branch information
johanjanssens committed Sep 4, 2018
1 parent c120bdb commit d8fff21
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions code/site/components/com_pages/data/object.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ public function slice($offset, $length = NULL)
return new self($data);
}

public function filter($key, $value = null)
{
$data = $this->toArray();

$data = array_filter($data, function($v) use ($key, $value)
{
if($value !== null) {
return (isset($v[$key]) && $v[$key] === $value);
} else {
return isset($v[$key]);
}
});

return new self($data);
}

public function __debugInfo()
{
return self::unbox($this);
Expand Down

0 comments on commit d8fff21

Please # to comment.