检查变量是否存在且=== true [英] Check if Variable exists and === true

查看:86
本文介绍了检查变量是否存在且=== true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想查看是否:


  • 数组中的字段isset

  • 字段=== true

是否可以通过一个检查这个语句?

Is it possible to check this with one if statement?

检查 === 是否可以解决问题,但会抛出PHP通知。我是否真的必须检查字段是否设置然后是否为真?

Checking if === would do the trick but a PHP notice is thrown. Do I really have to check if the field is set and then if it is true?

推荐答案

如果你想要它在一个单一的声明



If you want it in a single statement:

if (isset($var) && ($var === true)) { ... }






如果你想要一个条件



嗯,您可以忽略该通知(也就是使用 error_reporting() 功能)。


If you want it in a single condition:

Well, you could ignore the notice (aka remove it from display using the error_reporting() function).

或者你可以用邪恶的 @ 字符:

Or you could suppress it with the evil @ character:

if (@$var === true) { ... }




此解决方案 NOT RECOMMENDED

这篇关于检查变量是否存在且=== true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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