-1

I'm setting a variable to 1 or 2 and than later I want to check to see if the variable is 2 to execute an if statement but not sure I have the syntax right

if( $card_number=2 )
{
    Do this
}

So above this $card_number will be set to either 1 or 2 and I'm trying to do an if statement that if it is 2 than perform this, but the way I have it doesn't seem to be working.

Greenhoe
  • 971
  • 4
  • 14
  • 39
  • 3
    Use `==` or `===`, and to test for two values use `||`, e.g. `if ($card_number == 1 || $card_number == 2) ...` – p.s.w.g May 23 '14 at 21:48
  • What is the difference between == and ===? – Greenhoe May 23 '14 at 21:48
  • [How do the PHP equality (== double equals) and identity (=== triple equals) comparison operators differ?](http://stackoverflow.com/questions/80646/how-do-the-php-equality-double-equals-and-identity-triple-equals-comp) – p.s.w.g May 23 '14 at 21:49
  • == means value equals, === means value and type equals. 1=="1" is true, but 1==="1" is false because one is an integer amd one is a string. – Matthew Johnson May 23 '14 at 21:50
  • ah, silliest mistake everrrrr!!!!!! Have you bothered binging if statements. LOL, bing. –  May 24 '14 at 00:51

1 Answers1

1

You are assigning the value 2 to $card_number by using "=". You have to use "==" or "===".

"==" -> check value regardless of the type. So (string) "2" == 2 will be true, but "2" === 2 will be false.

WebMentor
  • 46
  • 1