summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md9
-rw-r--r--src/Reader.php4
2 files changed, 8 insertions, 5 deletions
diff --git a/README.md b/README.md
index 1556962..70ac274 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 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(