Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ResultsParser
- {
- function generateTrainSchedulesFromArray(array $inputSchedule)
- {
- /*Declare a new array of train schedules.*/
- $trainSchedules = new SplDoublyLinkedList();
- /*Begin loop*/
- $currentTrainStationId = null;
- $lastTrainStationId = null;
- $trainSchedule = null;
- foreach ($inputSchedule as $key => $row) {
- $currentTrainStationId = $row[0];
- print $currentTrainStationId;
- /*While the current station ID is equal to the last station ID and there exists a next element in the array.*/
- if ($currentTrainStationId != $lastTrainStationId) {
- /*If we get here we want to push the results generated below to the array given the ID mismatch
- Then we want to create a new schedules object.*/
- $trainSchedule = new trainSchedule($currentTrainStationId);
- $trainSchedules->push($trainSchedule);
- }
- $stationScheduled = new StationSchedule($row[1], $row[2], $row[3]);
- $trainSchedule->push($stationScheduled);
- $lastTrainStationId = $row[0];
- }
- var_dump($trainSchedules);
- return $trainSchedules;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement