fork download
  1. <?php
  2. $mass = array(
  3. 10,
  4. 20,
  5. 100,
  6. 30,
  7. 40,
  8. 104,
  9. 200,
  10. 202,
  11. 33
  12. );
  13. $lastValue1 = $mass[0];
  14. $lastValue2 = $mass[1];
  15. $lastDef = abs($mass[0] - $mass[1]);
  16. $k = 1;
  17.  
  18. for ($i = 1; $i < count($mass); $i++) {
  19. $k = 0;
  20. do {
  21.  
  22. $def = abs($mass[$k] - $mass[$i]);
  23.  
  24. if ($def == 0) {
  25. continue;
  26. }
  27. if ($def < $lastDef) {
  28. $lastDef = $def;
  29. $lastValue2 = $mass[$k];
  30. $lastValue1 = $mass[$i];
  31. }
  32. $k++;
  33. } while ($k < $i);
  34.  
  35. }
  36. echo "$lastValue1<br>";
  37. echo "$lastValue2<br>";
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
202<br>200<br>