0

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.

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.