来自JSON数据的PHP IF函数

I have the following data, when doing var_dump() on my data:

  ["time_zone"]=>
   string(6) "London"
  ["geo_enabled"]=>
   bool(false)
  ["verified"]=>
   bool(true)

I can do the following to access the string "London": $UserTimeZone = $userProfile->time_zone;

However I also need to be able to determine whether the "verified" bool value is true/false.

How can I write an if to check if the "verified" bool value is true/false.

I've tried the following and it isn't working it always returns - not verified:

$verified->verified;

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

Any help appreciated.

It doesn't look like you are actually setting the variable $verified, in which case it would always result as false in your if statement.

$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";
}

Or, you could do:

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

This way you don't have to worry about setting any extra variables, you're just accessing what is stored in the object.