0

Hi I wanna do something like this

<?php
$a = 0 ;
$b = 1 ;
$MyCondition = "$a < $b" ;

if ($MyCondition) // should be if($a < $b) !
    //DoSomething
?>

HOW to do it ? Thank you !

Mor Cohen
  • 101
  • 1
  • 9
  • @Gordon I tried to build a function which evaluates an expression in a string. I succeeded doing it using `eval()` – Mor Cohen Jul 30 '13 at 16:45
  • @MorCohen thanks for the update. Now that you know that you can use eval, check http://stackoverflow.com/questions/951373/when-is-eval-evil-in-php and the answers in the linked dupe for better alternatives. – Gordon Jul 30 '13 at 16:50

2 Answers2

4
<?php
$a = 0 ;
$b = 1 ;
$MyCondition = $a < $b ;

if ($MyCondition) // 
    //DoSomething
?>
Maarty
  • 1,140
  • 1
  • 12
  • 27
0
$a = 2 ;
$b = 3 ;
$MyCondition = $a < $b ;

if ($MyCondition){
  echo "true";
}else{
  echo "false";
}

I don't see why though, when you can just use

if ($a < $b)
Ben Fortune
  • 31,623
  • 10
  • 79
  • 80