samedi 25 mai 2019

Pass variable as condition for if statement in php

I have dynamic condition for if statement that stored as a variable. How to make if statement worked using that variable as as its condition?

I have tried using eval function but it's still didn't work

Here is my code:

$a = 2;
$b = 2;
$c = '$a==$b';
$d = eval('return $c;');

if($d === true){
    echo 'yes';
}
else{
    echo 'no';
}

It should be return 'yes', but my current code return 'no'.

Aucun commentaire:

Enregistrer un commentaire