Documentation

TabularDataReader extends TabularData, IteratorAggregate, Countable

Represents a Tabular data.

Tags
template
template-extends

Table of Contents

Methods

count()  : int
Returns the number of records contained in the tabular data structure excluding the header record.
fetchColumn()  : Iterator<int, mixed>
Returns a single column from the next record of the tabular data.
fetchOne()  : array<string|int, mixed>
DEPRECATION WARNING! This method will be removed in the next major point release.
fetchPairs()  : Iterator
Returns the next key-value pairs from the tabular data (first column is the key, second column is the value).
getHeader()  : array<string|int, string>
Returns the header associated with the tabular data.
getIterator()  : Iterator<string|int, TValue>
Returns the tabular data rows as an iterator object containing flat array.
getRecords()  : Iterator<string|int, array<string|int, mixed>>
Returns the tabular data records as an iterator object.

Methods

count()

Returns the number of records contained in the tabular data structure excluding the header record.

public count() : int
Return values
int

fetchColumn()

Returns a single column from the next record of the tabular data.

public fetchColumn([string|int $index = 0 ]) : Iterator<int, mixed>

By default, if no value is supplied the first column is fetched

Parameters
$index : string|int = 0

CSV column index

Tags
throws
UnableToProcessCsv

if the column index is invalid or not found

Return values
Iterator<int, mixed>

fetchOne()

DEPRECATION WARNING! This method will be removed in the next major point release.

public fetchOne([int $nth_record = 0 ]) : array<string|int, mixed>

since version 9.9.0

Returns the nth record from the tabular data.

By default, if no index is provided the first record of the tabular data is returned

use League\Csv\TabularDataReader::nth() instead

Parameters
$nth_record : int = 0

the tabular data record offset

Tags
throws
UnableToProcessCsv

if argument is less than 0

Return values
array<string|int, mixed>

fetchPairs()

Returns the next key-value pairs from the tabular data (first column is the key, second column is the value).

public fetchPairs([string|int $offset_index = 0 ][, string|int $value_index = 1 ]) : Iterator

By default, if no column index is provided:

  • the first column is used to provide the keys
  • the second column is used to provide the value
Parameters
$offset_index : string|int = 0

The column index to serve as offset

$value_index : string|int = 1

The column index to serve as value

Tags
throws
UnableToProcessCsv

if the column index is invalid or not found

Return values
Iterator

getHeader()

Returns the header associated with the tabular data.

public getHeader() : array<string|int, string>

The header must contain unique string or be an empty array if no header is specified.

Return values
array<string|int, string>

getIterator()

Returns the tabular data rows as an iterator object containing flat array.

public getIterator() : Iterator<string|int, TValue>

Each row is represented as a simple array containing values.

If the tabular data has a header included as a separate row then each record is combined to the header record and the header record is removed from the iteration.

If the tabular data is inconsistent. Missing fields are filled with null values while extra record fields are strip from the returned array.

Return values
Iterator<string|int, TValue>

getRecords()

Returns the tabular data records as an iterator object.

public getRecords([array<int, string> $header = [] ]) : Iterator<string|int, array<string|int, mixed>>

Each record is represented as a simple array containing strings or null values.

If the tabular data has a header record then each record is combined to the header record and the header record is removed from the iterator.

If the tabular data is inconsistent. Missing record fields are filled with null values while extra record fields are strip from the returned object.

Parameters
$header : array<int, string> = []

an optional header mapper to use instead of the tabular data header

Return values
Iterator<string|int, array<string|int, mixed>>

        
On this page

Search results