Skip to content

Commit

Permalink
Update Reader::fetchOne and Reader::fetchCol default values
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Feb 17, 2014
1 parent b329f40 commit 4cbd9e3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,13 @@ $data = $reader->fetchAssoc(['firstname', 'lastname', 'email']);
> * If the number of values in a CSV row is lesser than the number of named keys, the method will add `null` values to compensate for the missing values.
> * If the number of values in a CSV row is greater that the number of named keys the exceeding values will be drop from the result set.
#### fetchCol($columnIndex, $callable = null)
#### fetchCol($columnIndex = 0, $callable = null)

`fetchCol` returns a sequential array of all values in a given column from the CSV data.

* If no argument is given to the method it will return the first colum from the CSV data.
* If the column does not exists in the csv data the method will return an array full of null value.

```php
$data = $reader->fetchCol(2);
// will return something like this :
Expand All @@ -247,9 +250,9 @@ The methods listed above (`fetchAll`, `fetchAssoc`, `fetchCol`) can all take a o
* the current csv key
* the current csv Iterator Object

#### fetchOne($offset)
#### fetchOne($offset = 0)

`fetchOne` return one single row from the CSV data. The required argument `$offset` represent the row index starting at 0.
`fetchOne` return one single row from the CSV data. The required argument `$offset` represent the row index starting at 0. If no argument is given to the method it will return the first row from the CSV data.

```php
$data = $reader->fetchOne(3); ///accessing the 4th row (indexing starts at 0)
Expand Down
4 changes: 2 additions & 2 deletions src/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function query(callable $callable = null)
*
* @throws \InvalidArgumentException If the $offset is not a valid Integer
*/
public function fetchOne($offset)
public function fetchOne($offset = 0)
{
$this->setOffset($offset);
$this->setLimit(1);
Expand Down Expand Up @@ -170,7 +170,7 @@ public function fetchAssoc(array $keys, callable $callable = null)
*
* @throws \InvalidArgumentException If the column index is not a positive integer or 0
*/
public function fetchCol($columnIndex, callable $callable = null)
public function fetchCol($columnIndex = 0, callable $callable = null)
{
if (false === filter_var($columnIndex, FILTER_VALIDATE_INT, ['options' => ['min_range' => 0]])) {
throw new InvalidArgumentException(
Expand Down

0 comments on commit 4cbd9e3

Please sign in to comment.