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