public function QueryPath::slice in QueryPath 7.2
Same name and namespace in other branches
- 6 QueryPath/QueryPath.php \QueryPath::slice()
- 7.3 QueryPath/QueryPath.php \QueryPath::slice()
File
- QueryPath/
QueryPath.php, line 585
Class
Code
public function slice($start, $length = 0) {
$end = $length;
$found = new SplObjectStorage();
if ($start >= $this
->size()) {
$this
->setMatches($found);
return $this;
}
$i = $j = 0;
foreach ($this->matches as $m) {
if ($i >= $start) {
if ($end > 0 && $j >= $end) {
break;
}
$found
->attach($m);
++$j;
}
++$i;
}
$this
->setMatches($found);
return $this;
}