Hello. There is a txt file that contains many lines. I bring this file to the page, breaking into lines. After that, I select only those rows, elements of the array, which consist of 20 elements. I take the first and second word (this is the date and time) from each line. And it turns out something like:
2018/01/15 15:00:00 2018/01/15 15:00:00 2018/01/15 16:00:00 2018/01/15 18:00:00 2018/01/15 18:00:00 I need to get only lines with different dates at the output:
2018/01/15 15:00:00 2018/01/15 16:00:00 2018/01/15 18:00:00 $log = file_get_contents('./file.txt', FILE_USE_INCLUDE_PATH); $line = explode("\n", $log); foreach ($line as &$value_line) { $arr_line = explode(' ', $value_line); if (count($arr_line) == 20) { $dateTime = $arr_line[0]." ".$arr_line[1]; echo $dateTime; echo "<hr>"; } } How can I do it?
forinstead offoreach- Akubikif($old != $dateTime) { echo "$dateTime<hr>"; } $old=$dateTime;if($old != $dateTime) { echo "$dateTime<hr>"; } $old=$dateTime;- Mikeif (strcmp($dateTime; $arr_line[0]." ".$arr_line[1]))- Akubik