array (
1=> '215070121',
5=> '215001216',
12=> '215050121',
21=> '215010127',
50=> '215080122'
);
$price = 10;
function getClosest($search, $arr) {
$closest = null;
foreach ($arr as $price => $id) {
if ($closest === null || abs($search - $closest) > abs($price - $search)) {
$closest = $price;
}
}
return $arr[$closest];
}