Dynamic Comparison Operators in PHP

后端 未结 11 714
挽巷
挽巷 2020-12-03 11:24

Is it possible, in any way, to pass comparison operators as variables to a function? I am looking at producing some convenience functions, for example (and I know this won\'

11条回答
  •  醉酒成梦
    2020-12-03 11:48

    If you absolutely insist you can use eval.

    if(isset($var) && eval("return \$var $operator \$value"))
        return true;
    

    But I wouldn't recommend it.

提交回复
热议问题