Skip to content

Commit

Permalink
Update readme with object iteration information
Browse files Browse the repository at this point in the history
  • Loading branch information
ppetrov committed Sep 8, 2017
1 parent 1dcf1f4 commit b28c6bb
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();
```
Expand Down

0 comments on commit b28c6bb

Please sign in to comment.