The value itself has a symbol, how to integrate into if

$a = "> = 2";
$baked 0;
if ($b $a) {
}
how to write the code to get Boolean 0 > = 2 = > false

Php
Apr.01,2021

you can use eval, but there are security risks. The following processing methods are recommended

$a = '>=2';
$b = 0;
if (strpos($a, '>=') !== false) {
    $a = str_replace('>=','',$a);
    var_dump('>=', $b >= $a);
} elseif (strpos($a, '>') !== false) {
    $a = str_replace('>','',$a);;
    var_dump('>', $b > $a);
}
// ...
Menu