From b28c6bb04b8180b951fc18ce65bdfc97537d9f01 Mon Sep 17 00:00:00 2001 From: ppetrov Date: Fri, 8 Sep 2017 14:22:13 +0300 Subject: [PATCH] Update readme with object iteration information --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index a90cee9..7e3db8d 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,22 @@ To parse a simple CSV file, use the following code: use \Carbon_CSV\CsvFile as CsvFile; use \Carbon_CSV\Exception; +$csv = new CsvFile('path-to-file/filename.csv'); +foreach ($csv as $row) { + /* do something with $row*/ +} +``` + +You can iterate the `$csv` object directly, or get all the rows using the `to_array` method. + +**Important:** the above approach is preferred, as it's less taxing - memory wise (it only works with one row at a time, and doesn't hold all of them, like `to_array` does). + +Here's an example with the `to_array` method. + +```php +use \Carbon_CSV\CsvFile as CsvFile; +use \Carbon_CSV\Exception; + $csv = new CsvFile('path-to-file/filename.csv'); $rows = $csv->to_array(); ```