$arr = [300, 600, 900, 1200];
$number = 920;
$deltas = array_reduce(
$arr,
function($t, $v) use ($number) {
$t[$v] = abs($v - $number);
return $t;
},
[]
);
asort($deltas);
echo array_keys($deltas)[0];
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter