Skip to content

Commit

Permalink
fetchCol improved
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Jan 28, 2014
1 parent 12787f2 commit 020a790
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/Bakame/Csv/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,17 +307,16 @@ public function fetchCol($columnIndex, callable $callable = null, $strict = fals
}

$iterator = $this->query($callable);
$iterator = new MapIterator($iterator, function ($row) use ($columnIndex) {
if (! array_key_exists($columnIndex, $row)) {
$row[$columnIndex] = null;
}

return $row;
});
if ($strict) {
$iterator = new CallbackFilterIterator($iterator, function ($row) use ($columnIndex) {
return array_key_exists($columnIndex, $row);
});
} else {
$iterator = new MapIterator($iterator, function ($row) use ($columnIndex) {
if (! array_key_exists($columnIndex, $row)) {
$row[$columnIndex] = null;
}

return $row;
return array_key_exists($columnIndex, $row) && ! is_null($row[$columnIndex]);
});
}

Expand Down

0 comments on commit 020a790

Please sign in to comment.