<?php
$mass = array(10, 20, 100, 30, 40, 101, 200, 202, 32); $lastValue1 = $mass[0];
$lastValue2 = $mass[1];
$lastDef = abs($mass[0] - $mass[1]); foreach ($mass as $key => $value)
{
for ($i = 0; $i < count($mass); $i++) {
$def = abs ($value - $mass[$i]); if ($def == 0)
{
continue;
}
if ($def < $lastDef)
{
$lastDef = $def;
$lastValue1 = $value;
$lastValue2 = $mass[$i];
}
}
}
echo "$lastValue1<br>";
echo "$lastValue2<br>";
?>
PD9waHAKJG1hc3MgPSBhcnJheSgxMCwgMjAsIDEwMCwgMzAsIDQwLCAxMDEsIDIwMCwgMjAyLCAzMik7CiRsYXN0VmFsdWUxID0gJG1hc3NbMF07CiRsYXN0VmFsdWUyID0gJG1hc3NbMV07CiRsYXN0RGVmID0gYWJzKCRtYXNzWzBdIC0gJG1hc3NbMV0pOwpmb3JlYWNoICgkbWFzcyBhcyAka2V5ID0+ICR2YWx1ZSkKewkKCiBmb3IgKCRpID0gMDsgJGkgPCBjb3VudCgkbWFzcyk7ICRpKyspCiB7CiAJJGRlZiA9IGFicyAoJHZhbHVlIC0gJG1hc3NbJGldKTsKIAlpZiAoJGRlZiA9PSAwKQogCXsKCQljb250aW51ZTsKCX0KCWlmICgkZGVmIDwgJGxhc3REZWYpCgl7CgkJJGxhc3REZWYgPSAkZGVmOwoJCSRsYXN0VmFsdWUxID0gJHZhbHVlOwoJCSRsYXN0VmFsdWUyID0gJG1hc3NbJGldOwoJCQoJfQogfQoJCn0KZWNobyAiJGxhc3RWYWx1ZTE8YnI+IjsKZWNobyAiJGxhc3RWYWx1ZTI8YnI+IjsKCj8+