Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.31 KB | None | 0 0
  1. class ResultsParser
  2. {
  3.     function generateTrainSchedulesFromArray(array $inputSchedule)
  4.     {
  5.         /*Declare a new array of train schedules.*/
  6.         $trainSchedules = new SplDoublyLinkedList();
  7.         /*Begin loop*/
  8.        
  9.         $currentTrainStationId = null;
  10.         $lastTrainStationId = null;
  11.         $trainSchedule = null;
  12.        
  13.         foreach ($inputSchedule as $key => $row) {
  14.             $currentTrainStationId = $row[0];
  15.             print $currentTrainStationId;
  16.            
  17.             /*While the current station ID is equal to the last station ID and there exists a next element in the array.*/
  18.             if ($currentTrainStationId != $lastTrainStationId) {
  19.                 /*If we get here we want to push the results generated below to the array given the ID mismatch
  20.                 Then we want to create a new schedules object.*/
  21.                 $trainSchedule = new trainSchedule($currentTrainStationId);
  22.                 $trainSchedules->push($trainSchedule);
  23.             }
  24.            
  25.             $stationScheduled = new StationSchedule($row[1], $row[2], $row[3]);
  26.             $trainSchedule->push($stationScheduled);
  27.            
  28.             $lastTrainStationId = $row[0];
  29.         }
  30.        
  31.         var_dump($trainSchedules);
  32.         return $trainSchedules;
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement