php multiple if conditions

前端 未结 5 1945
既然无缘
既然无缘 2021-01-29 11:16

when i try to filter all these parameters php only enters in the first if conditions, ignoring all others conditions.

if($t_red<0){
    $t_red=0;
}

else if($         


        
5条回答
  •  时光取名叫无心
    2021-01-29 11:52

    Probably best suited if ran through a filtering function.

    function setParam($param) {
      if($param < 0) {
        $param = 0;
      } elseif($param > 256) {
        $param = 255;
      }
    
      return $param;
    }
    
    $t_green = setParam($t_green);
    $t_red = setParam($t_red);
    $t_blue = setParam($t_blue);
    

    You could also use pass-by-reference if necessary.

提交回复
热议问题