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)
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)
You can put the string into php eval() function.
$str = "1==1 && 1==1 && 2==1";
$question = eval("return $str;");
if ($question) {
} else {
}
I hope it will be usefull for you.
Try this code , i think you required this condition.
$array[] = "1==1";
$array[] = "1==1";
$array[] = "2==1";
$str = implode(" && ", $array);
$condition = eval("return $str;");
if($condition)
return "true code";
else
return "false code";