Dynamic conditions in PHP

The below example demonstrates how we can check dynamic conditions in PHP.

$var1 = 11;
$var2 = 110;
$cond1 = '$var1 > $var2';
$cond2 = '$var1 < $var2';

if(eval("return $cond1;")){
echo $cond1;
}

if(eval("return $cond2;")){
echo $cond2;
}

Leave a comment

Your email address will not be published. Required fields are marked *