From 020a790a93a787f80f388bf95b1221c32d52e503 Mon Sep 17 00:00:00 2001 From: Ignace Nyamagana Butera Date: Tue, 28 Jan 2014 10:29:44 +0100 Subject: [PATCH] fetchCol improved --- src/Bakame/Csv/Reader.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/Bakame/Csv/Reader.php b/src/Bakame/Csv/Reader.php index 8af5faae..f7811fdb 100644 --- a/src/Bakame/Csv/Reader.php +++ b/src/Bakame/Csv/Reader.php @@ -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]); }); }