PHP CSV, how to get previous and next 3 rows from current row

Posted by Kalpesh Mehta on Stack Overflow See other posts from Stack Overflow or by Kalpesh Mehta
Published on 2012-11-21T10:40:06Z Indexed on 2012/11/21 11:00 UTC
Read the original article Hit count: 186

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about php

Related posts about csv