EasyCSV\Reader::advanceTo PHP Method

advanceTo() public method

public advanceTo ( $lineNumber )
$lineNumber zero-based index
    public function advanceTo($lineNumber)
    {
        if ($this->headerLine > $lineNumber) {
            throw new \LogicException("Line Number {$lineNumber} is before the header line that was set");
        } elseif ($this->headerLine === $lineNumber) {
            throw new \LogicException("Line Number {$lineNumber} is equal to the header line that was set");
        }
        if ($lineNumber > 0) {
            $this->handle->seek($lineNumber - 1);
        }
        // check the line before
        if ($this->isEof()) {
            throw new \LogicException("Line Number {$lineNumber} is past the end of the file");
        }
        $this->handle->seek($lineNumber);
    }

Usage Example

示例#1
0
 /**
  * @dataProvider getReadersNoHeadersFirstRow
  */
 public function testAdvanceToNoHeadersFirstRow(Reader $reader)
 {
     $row = array(0 => 'Some Meta Data', 1 => '', 2 => '');
     $actualRow = $reader->getRow();
     $this->assertEquals($row, $actualRow);
     // give it the ol' one-two-switcharoo
     $reader->advanceTo(3);
     $reader->getRow();
     $reader->advanceTo(0);
     $this->assertEquals($row, $reader->getRow());
 }
All Usage Examples Of EasyCSV\Reader::advanceTo