Using a variable as an operator

后端 未结 11 1448
滥情空心
滥情空心 2020-12-06 09:31

So I have something like the following:

$a = 3;
$b = 4;
$c = 5;
$d = 6;

and I run a comparison like

if($a>$b || $c>$d         


        
11条回答
  •  独厮守ぢ
    2020-12-06 09:44

    No, that syntax isn't available. The best you could do would be an eval(), which would not be recommended, especially if the $e came from user input (ie, a form), or a switch statement with each operator as a case

    switch($e)
    {
        case "||":
            if($a>$b || $c>$d)
                echo 'yes';
        break;
    }
    

提交回复
热议问题