fork download
  1. <?php
  2. $p = array();
  3. $p[] = array(1,new DateTimeImmutable('2016-12-11 17:00'),True);
  4. $p[] = array(2,new DateTimeImmutable('2016-12-11 17:01'),True);
  5. $p[] = array(1,new DateTimeImmutable('2016-12-11 17:03'),True);
  6. $p[] = array(3,new DateTimeImmutable('2016-12-11 17:04'),True);
  7. $p[] = array(2,new DateTimeImmutable('2016-12-11 17:06'),True);
  8. $p[] = array(3,new DateTimeImmutable('2016-12-11 17:06'),True);
  9. $p[] = array(1,new DateTimeImmutable('2016-12-11 17:07'),True);
  10. $p[] = array(2,new DateTimeImmutable('2016-12-11 17:07'),True);
  11. $p[] = array(3,new DateTimeImmutable('2016-12-11 17:07'),True);
  12. $p[] = array(1,new DateTimeImmutable('2016-12-11 17:11'),True);
  13. $p[] = array(3,new DateTimeImmutable('2016-12-11 17:12'),True);
  14.  
  15.  
  16. for ($i = 0; $i < count($p) - 1; $i++){
  17. for ($j = $i+1; $j < count($p); $j++){
  18. if ($p[$i][0] == $p[$j][0] && $p[$i][2] == True) {
  19. if (($p[$i][1] <= $p[$j][1] &&
  20. $p[$j][1] <= $p[$i][1]->modify('+5 minutes'))){
  21. $p[$j][2] = False;
  22. }
  23. }
  24.  
  25. }
  26. }
  27. for ($i = 0, $count = 0; $i < count($p); $i++){
  28. if ($p[$i][2] == True) {
  29. print $p[$i][0]." ".$p[$i][1]->format('Y-m-d H:i')."\n";
  30. $count++;
  31. }
  32. }
  33. print $count."件です\n";
  34. ?>
Success #stdin #stdout 0.01s 52488KB
stdin
Standard input is empty
stdout
1 2016-12-11 17:00
2 2016-12-11 17:01
3 2016-12-11 17:04
1 2016-12-11 17:07
2 2016-12-11 17:07
3 2016-12-11 17:12
6件です