PHP Read CSV and filter by date

前端 未结 6 2097
再見小時候
再見小時候 2021-01-24 08:12

I have the following CSV

Date,Event,Description
24/01/2010,Football,Football practice for all Years.
24/01/2010,Cricket,Cricket Practice for all Years.
25/01/201         


        
6条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-24 08:27

    There are pretty much many ways to read a CSV files; you can also read in line by line and use the split function to separate each filed as an element in an array.

    If search speed and complexity is not a concern, you can do a linear iteration and check for dates. You may want to use strtotime to convert the date into a unix timestamp for comparison.

    If the search speed is important, then convert the date to timestamp, have an associative array which key is the timestamp (essentially a hash table)

    To get tomorrow's date, check out the date function documentation in the PHP manual.

提交回复
热议问题