2

Please help me and correct where I'm wrong. Below is my code when timezone is UK it will print else part why really don't understand.

  $user = User::find(BaseHelper::getCurrentUser());
  if($user->timezone ='UK')
  {
      $date = Carbon::createFromFormat('Y-m-d H:i:s', $this->updated, 'GMT');
      $date->timezone("Europe/London");
  } else {
      $date = Carbon::parse($this->updated)->format('d/m/Y h:i A');
  }

2 Answers 2

7

You are using if($user->timezone ='UK') equal here, when you should use ==

= is for assignment and == is for comparing value.

if($user->timezone ='UK')

will not return true because the value is stored successfully in a variable.

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

Comments

1

You need to change this if($user->timezone ='UK') to this if($user->timezone == "UK"). This will check if $user->timezone equals UK.


If you're tried to set the value of $user->timezone to UK you need to use =, otherwise you need to use == or ===


$a = $b

  • Set $a value to $b

$a == $b

  • Equal true: if $a is equal to $b, after type juggling.

$a === $b

  • Identical true: if $a is equal to $b, and they are of the same type.

10 Comments

I changed this then it is taking else part
Something weird is happening dont know why cause when i use '=' then in both condition it is taking if part and when i use '==' then for both condition it is taking else part
can you dump($user->timezone) and see if the value timezone is equal to UK
yes for dump when timezone is available it is showing UK or else blank
Are you now using == or ===?
|

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.