Open GoogleCodeExporter opened 9 years ago
With my limited understanding of the codebase, this seems to be effective with
no
negative repercussions:
+ 90| # build the data array with associative keys
+ 91| var $assoc_key= false;
+ 92|
-449| $key = ( !empty($head[$col]) ) ? $head[$col] : $col ;
+449| $key = ( !empty($head[$col]) && $this->assoc_key ) ? $head[$col] : $col ;
Original comment by teh.a...@gmail.com
on 7 Jul 2008 at 5:29
Good point :)
However, at the moment I'm planning on implementing this with an option, rather
than just filling one array
with associative data, and one with indexed data, effectively consuming nearly
twice the amount of memory
otherwise used.
So by default, I'll probably leave parseCSV working as it is now, but with an
option to enable a indexed array
aswell simply using numbers for key names for each field in a row.
My main reason behind this approach right now is to keep things backwards
compatible. However, I might
endup doing something different once I start messing with the code.
I'll keep this issue updated at what I'll do :)
Original comment by zynode
on 10 Jul 2008 at 6:47
I'm not sure I understand what you're saying - the solution I posted doesn't
create
an additional array, it just changes what key is used to initially store the
data
into parseCSV::$data.
Original comment by teh.a...@gmail.com
on 10 Jul 2008 at 8:54
Damn, you're right. Not sure what I was thinking last night when I posted that.
I knew +24 hours awake and
trying to do stuff that requires brain cells was a bad idea... lol
Now that I've actually got a functioning head, your solution is pretty much
exactly what I in mind, except I'm
planning to have few different values of the assoc_key which will change how
the data is output. As in make
parseCSV::$data use key names, parseCSV::$index_data (example name only) use
key numbers, or have the
values in key names and numrical values both in the main array.
Also, currently you can access data more or less like the way you want without
using offset. Simply parse the
file as normal, and call $csv->data[$row][$csv->titles[2]]; to access the 3rd
column. It's not as pretty as the
final solution will be.
P.S. Sorry for being dumber than a 2 year old last night... lol :$
Original comment by zynode
on 11 Jul 2008 at 5:21
my CSV file not have title and your solution escape 1st row of file.
Original comment by mohamed....@gmail.com
on 16 Dec 2014 at 1:38
You can disable the heading/title feature of the parser by setting
$csv->heading to false.
If you still have any issues, please report them on Github instead of here:
https://github.com/parsecsv/parsecsv-for-php
Original comment by zynode
on 16 Dec 2014 at 11:20
Original issue reported on code.google.com by
teh.a...@gmail.com
on 7 Jul 2008 at 2:02