-
-
Notifications
You must be signed in to change notification settings - Fork 339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Many, many times it is written in the documentation differently than it actually is. #551
Comments
@gander thanks for using the package could you provide an example of what you are describing because I fail to understand the actual issue you are referring to 🤔 |
CSV with header row $reader = Reader::createFromStream(fopen(__DIR__.'/input.csv', 'r'))
->setHeaderOffset(0)
->getRecords()
; Result:
Should be:
|
Following documentation, $records = $reader->getRecords($reader->getHeader()); |
For now, my workaround: $reader = Reader::createFromStream(fopen(__DIR__.'/input.csv', 'r'));
$header = $reader->slice(0, 1)->first();
$records = iterator_to_array($reader->slice(1)); |
You are incorrect ... it is doing exactly what it is said in the documentation. By setting the header offset you are instructing the If you wish not to use the header offset and have it included in your CSV object just do not use So this is definitely not a bug but expected behaviour. |
So how do you use setHeaderOffset, get the header, and have the records not mapped with the header? |
if you do not care about the header being set just iterate over the value and use $reader = Reader::createFromPath(__DIR__.'/input.csv', 'r');
$reader->setHeaderOffset(0);
iterator_to_array($reader->map(fn (array $row) => array_values($row))) |
Still need header, some data mapped, and not mapped, so my workaround $header = $reader->slice(0, 1)->first();
$reader->slice(666, 1)->mapHeader($header)->first(); |
I still think that there is room for improvement, but in the documentation. In one place it says that |
I really do not understand what you are trying to achieve but I guess it serves your business logic and that's fine. The only thing I know it's that what you are doing is not a workaround because there is no bug to work around 🤷🏾♂️ |
Bug Report
Many, many times it is written in the documentation differently than it actually is.
Summary
e.g. here https://csv.thephpleague.com/9.0/reader/tabular-data-reader/
getRecords
Currently, each call to
getRecords()
returns a records mapped from headers. Each method returns mapped if I have setsetHeaderOffset
.The text was updated successfully, but these errors were encountered: