You are here

public function QueryPath::slice in QueryPath 6

Same name and namespace in other branches
  1. 7.3 QueryPath/QueryPath.php \QueryPath::slice()
  2. 7.2 QueryPath/QueryPath.php \QueryPath::slice()

File

QueryPath/QueryPath.php, line 585

Class

QueryPath

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;
}