From 4cbd9e3f428e17ea4888ad7bf9a8cc12be0ee318 Mon Sep 17 00:00:00 2001 From: Ignace Nyamagana Butera Date: Mon, 17 Feb 2014 14:39:35 +0100 Subject: [PATCH] Update Reader::fetchOne and Reader::fetchCol default values --- README.md | 9 ++++++--- src/Reader.php | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 15569620..70ac274d 100644 --- a/README.md +++ b/README.md @@ -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 : @@ -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) diff --git a/src/Reader.php b/src/Reader.php index ee7ac6b2..45a597a9 100644 --- a/src/Reader.php +++ b/src/Reader.php @@ -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); @@ -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(