<?php
ini_set('date.timezone', 'Europe/London');
class OnlyPendingDeletionIterator extends FilterIterator implements Countable {
public function __construct(array $items) {
parent::__construct(new ArrayIterator($items));
}
public function accept() {
$item = $this->current();
$fourthOfJan = strtotime('2014-01-04');
return $fourthOfJan > strtotime($item['date']);
}
public function count() {
return iterator_count($this);
}
}
$items = array(
array('id' => 1, 'date' => '2014-01-01'),
array('id' => 2, 'date' => '2014-01-02'),
array('id' => 3, 'date' => '2014-01-03'),
array('id' => 4, 'date' => '2014-01-04'),
array('id' => 5, 'date' => '2014-01-05'),
array('id' => 6, 'date' => '2014-01-06'),
array('id' => 7, 'date' => '2014-01-07'),
);
$items = new OnlyPendingDeletionIterator($items);
echo 'Pending: ', count($items), PHP_EOL;
foreach ($items as $item) {
echo 'id: ', $item['id'], PHP_EOL;
}
preferences:
37.19 ms | 402 KiB | 5 Q