\League\CsvResultSet

Represents the result set of a {@link Reader} processed by a {@link Statement}.

Summary

Methods
Properties
Constants
__construct()
__destruct()
getHeader()
getRecords()
getIterator()
count()
jsonSerialize()
fetchOne()
fetchColumn()
fetchPairs()
No public properties found
No constants found
getColumnIndex()
getColumnIndexByValue()
getColumnIndexByKey()
$records
$header
N/A
No private methods found
No private properties found
N/A

Properties

$records

$records : \Iterator

The CSV records collection.

Type

\Iterator

$header

$header : array

The CSV records collection header.

Type

array

Methods

__construct()

__construct(\Iterator  $records, array  $header) 

New instance.

Parameters

\Iterator $records

a CSV records collection iterator

array $header

the associated collection column names

__destruct()

__destruct() 

{@inheritdoc}

getHeader()

getHeader() : array<mixed,string>

Returns the header associated with the result set.

Returns

array<mixed,string>

getRecords()

getRecords() 

{@inheritdoc}

getIterator()

getIterator() 

{@inheritdoc}

count()

count() 

{@inheritdoc}

jsonSerialize()

jsonSerialize() 

{@inheritdoc}

fetchOne()

fetchOne(integer  $nth_record) 

Returns the nth record from the result set.

By default if no index is provided the first record of the resultet is returned

Parameters

integer $nth_record

the CSV record offset

Throws

\League\Csv\Exception

if argument is lesser than 0

fetchColumn()

fetchColumn(string|integer  $index) 

Returns a single column from the next record of the result set.

By default if no value is supplied the first column is fetch

Parameters

string|integer $index

CSV column index

fetchPairs()

fetchPairs(string|integer  $offset_index, string|integer  $value_index = 1) 

Returns the next key-value pairs from a result set (first column is the key, second column is the value).

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

string|integer $offset_index

The column index to serve as offset

string|integer $value_index

The column index to serve as value

getColumnIndex()

getColumnIndex(string|integer  $field, string  $error_message) : string|integer

Filter a column name against the header if any.

Parameters

string|integer $field

the field name or the field index

string $error_message

the associated error message

Returns

string|integer

getColumnIndexByValue()

getColumnIndexByValue(\League\Csv\string  $value, \League\Csv\string  $error_message) 

Returns the selected column name.

Parameters

\League\Csv\string $value
\League\Csv\string $error_message

Throws

\League\Csv\Exception

if the column is not found

getColumnIndexByKey()

getColumnIndexByKey(\League\Csv\int  $index, \League\Csv\string  $error_message) : integer|string

Returns the selected column name according to its offset.

Parameters

\League\Csv\int $index
\League\Csv\string $error_message

Throws

\League\Csv\Exception

if the field is invalid or not found

Returns

integer|string