<?php
/*
Open the CSV file for reading (r)
*/
$csv = new SplFileObject('path/to/file.csv', 'r');
/*
Tell the object that this file should
be treated as a CSV
*/
$csv->setFlags(SplFileObject::READ_CSV);
/*
Wrap the CSV file in a filter which
skips the first line
*/
$csv = new LimitIterator($csv, 1);
/*
Loops over the CSV file, the SplFileObject
automatically creates an array for you
*/
foreach($csv as $line){
var_dump($line); #it's a numerically indexed array
}
The flag is set to true outside the loop.
The first line gets read.
The IF statement finds that the flag is true; sets the flag to false, and goes back to the beginning of the loop (Continue)
The second line gets read. Now the flag is false, so the if doesnt execute, and the code procedes as normal.
I used StarLion’s modification although I am not quite sure how it works. It works though!! But if I don’t understand why it works then I have only hacked it.
I will try your idea out as well,… I will have to look at it a bit and see how to work it into my code.
As I am writing this I see StarLion’s reply,… oh my I cannot keep up with you guys
Thanks so much,
I really think I found a good forum at last!!!
That is what I was thinking but I wasn’t sure. It sure was an “easy” way to fix this issue. I do want to get into Anthoy’s idea too.
I am by no means a guru but I am well along in this crazy language and am hooked!
I keep getting deeper and deeper and have found there is no end to learning,…