3 回答
TA贡献1856条经验 获得超5个赞
如果 3 个变量的值可以更改,您可以使用它。可能有更简洁的方法,但这应该有效。
//Set users percentile
$user_percentile = 35;
$user_percentile_category = 25;
switch ($user_percentile) {
case $user_percentile <= $twentyfive:
$user_percentile_category = '25';
break;
case ($user_percentile - $twentyfive) < $fifty - $user_percentile:
$user_percentile_category = '25';
break;
case ($user_percentile - $twentyfive) >= $fifty - $user_percentile:
$user_percentile_category = '50';
break;
case ($user_percentile - $fifty) < $seventyfive - $user_percentile:
$user_percentile_category = '50';
break;
case ($user_percentile - $fifty) >= $seventyfive - $user_percentile:
$user_percentile_category = '75';
break;
default:
$user_percentile_category = '75';
}
TA贡献1802条经验 获得超6个赞
您可以使用以下代码:
function getClosest($search, $arr) {
$closest = null;
foreach ($arr as $item) {
if ($closest === null || abs($search - $closest) > abs($item - $search)) {
$closest = $item;
}
}
return $closest;
}
$collection = [55,80,95];
$searchValue = 88;
echo getClosest($searchValue, $collection);
TA贡献1829条经验 获得超6个赞
if($percentile < 67.5){
echo $twentyfive
} elseif($percentile > 67.5 && $percentile < 87.7){
echo $fifty
}else{
echo $seventyfive
}
- 3 回答
- 0 关注
- 138 浏览
添加回答
举报