如何在PHP的IF条件下使用字符串

如何在PHP的IF条件下使用字符串

问题描述:

我有数组
我已使用爆破功能将数组转换为字符串,例如
i以下需要$ str变量作为if语句的条件,如下所示

I have array I have converted the array into string using implode function like below i need the $str variable as condition in if statement like below

[0]=>"1==1" 
[1]=>"1==1" 
[2]=>"2==1"
$str = "1==1 && 1==1 && 2==1";
if(1==1 && 1==1 && 2==1)


尽管这不是进行此类活动的好方法,但是您可以使用 eval()为此:

Though it is not a good way to do such activity, you can use eval() for this:

<?php

$str = "1==1 && 1==1 && 2==1";

$condition = eval("return $str;");

if($condition) {
    echo "True";
} else {
    echo "False";
}

演示用于虚假情况

演示真实情况