php变量作为条件赋值 [英] php variable as conditional assignment

查看:63
本文介绍了php变量作为条件赋值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何将条件赋值分配给php变量,并在其他条件条件中使用它,例如:

I was wondering how can I asign a conditional assignment to a php variable and use it inside other conditional, like this:

$cndtnal='&& $x==4'

if($y==5 $cndtnal){
   print 'Hello World';
}

谢谢。

推荐答案

您应该尽量避免使用 eval ,但是如果要使用它,则可以这样做:

You should try avoiding the use of eval as much as possible, but if you want to use it, then you could do:

$cndtnal='&& $x=4';
if($y==5 .eval("return '$cndtnal';")  ){
   echo 'Hello World';
}
else {
    echo "this";
}

这篇关于php变量作为条件赋值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆