Search code examples
phpcomparison

Get comparison in PHP when equality sign is s string


I have two variables:

a = 5;
b = " > 6"

How could I get "true" or "false" for the comparison "5 > 6" using just a and b?


Solution

  • You can use PHP's eval function. But I would highly discourage you from using it and so do the PHP documentation.

    The eval() language construct is very dangerous because it allows execution of arbitrary PHP code. Its use thus is discouraged. If you have carefully verified that there is no other option than to use this construct, pay special attention not to pass any user provided data into it without properly validating it beforehand.