Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
来自JSON数据的PHP IF函数_Php - Fatal编程技术网

来自JSON数据的PHP IF函数

来自JSON数据的PHP IF函数,php,Php,在对我的数据执行var_dump()时,我有以下数据: ["time_zone"]=> string(6) "London" ["geo_enabled"]=> bool(false) ["verified"]=> bool(true) 我可以执行以下操作来访问字符串“London”:$UserTimeZone=$userProfile->timezone 但是,我还需要能够确定“verified”bool值是否为真/假 如何编写if以检查“已验

在对我的数据执行var_dump()时,我有以下数据:

  ["time_zone"]=>
   string(6) "London"
  ["geo_enabled"]=>
   bool(false)
  ["verified"]=>
   bool(true)
我可以执行以下操作来访问字符串
“London”
$UserTimeZone=$userProfile->timezone

但是,我还需要能够确定
“verified”
bool值是否为真/假

如何编写if以检查
“已验证”
布尔值是否为真/假

我尝试了以下方法,但不起作用。它总是返回-未验证:

$verified->verified;

if ($verified) {
  echo "verified";
} else {
  echo "not verified";
}

感谢您的帮助。

看起来您并不是在实际设置变量$verified,在这种情况下,if语句中的结果总是false

$verfied->$verified; // This isn't setting the variable $verified to anything.

$verified = $userProfile->verified; // This sets the variable $verified to what is stored in your user profile object

if ($verified) {
  echo "verified";
} else {
  echo "not verified";
}
或者,你可以:

if ($userProfile->verified) {
  echo "verified";
} else {
  echo "not verified";
}
这样,您就不必担心设置任何额外的变量,只需访问存储在对象中的内容