Dynamic conditions in PHP

Share

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;
}
This entry was posted in PHP and tagged . Bookmark the permalink.
 

Leave a Reply

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

*