How to use if condition inside string in php

前端 未结 3 715
隐瞒了意图╮
隐瞒了意图╮ 2021-01-17 06:02

I want to know if there is a way to use something like this:

$t1=1;
$t2=2;
$t3=\"$t1>$t2\";

if($t3)
   echo \"Greater\";
else
   echo \"Smaller\";
         


        
3条回答
  •  清酒与你
    2021-01-17 06:51

    This looks like it should work, given the PHP eval page.

    $t1=1;
    $t2=2;
    $t3="return $t1>$t2;";
    
    if(eval($t3))
       echo "Greater";
    else
       echo "Smaller";
    

提交回复
热议问题