diff options
author | Ignace Nyamagana Butera <nyamsprod@gmail.com> | 2014-02-17 14:39:35 +0100 |
---|---|---|
committer | Ignace Nyamagana Butera <nyamsprod@gmail.com> | 2014-02-17 14:39:35 +0100 |
commit | 4cbd9e3f428e17ea4888ad7bf9a8cc12be0ee318 (patch) | |
tree | 68dba17665265312901497e5b4f30645676158b6 | |
parent | b329f401223e32e5b527ca6632ad003bbe234929 (diff) | |
download | csv-4cbd9e3f428e17ea4888ad7bf9a8cc12be0ee318.zip csv-4cbd9e3f428e17ea4888ad7bf9a8cc12be0ee318.tar.gz csv-4cbd9e3f428e17ea4888ad7bf9a8cc12be0ee318.tar.bz2 |
Update Reader::fetchOne and Reader::fetchCol default values4.2.0
-rw-r--r-- | README.md | 9 | ||||
-rw-r--r-- | src/Reader.php | 4 |
2 files changed, 8 insertions, 5 deletions
@@ -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 ee7ac6b..45a597a 100644 --- a/src/Reader.php +++ b/src/Reader.php @@ -102,7 +102,7 @@ class Reader extends AbstractCsv * * @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 @@ class Reader extends AbstractCsv * * @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( |