I am currently using fgetcsv in php to get rows in CSV file. For each row, I need it’s 3 previous rows and 3 next rows for some requirement.
while(($data = fgetcsv($handle, 5000, ",")) !== FALSE) {
//$data is current row data
//I need previous rows and next rows data
}
I don’t know how to try this, as each while iterate will be having the current row’s information.
Is there anything we can achieve this within the fgetcsv loop? I am also open for other alternatives for this problem.
You have to store these rows yourself.
I would do something like this:
If the data is too big to keep it all stored in an array, you could also opt to only store at most 7 rows, and operate on row 4: