0

Is there a way in php to write if $a equals 1 then $b is 2 and $c is 3?

if ($a == 1) $b=2 AND $c=3;

doesn't work. Or do I need to write all three of them separately?

WendiT
  • 595
  • 2
  • 9
  • 26
  • 1
    if($a == 1) { $b = 2; $c = 3; } – LF00 May 06 '17 at 06:15
  • 1
    Try making 2 lines of code each containing the code you want to execute. Use curly braces as well then. – Maarten Weyns May 06 '17 at 06:17
  • http://stackoverflow.com/questions/3737139/reference-what-does-this-symbol-mean-in-php – LF00 May 06 '17 at 06:22
  • I'm voting to close this question as off-topic because its very simple. – LF00 May 06 '17 at 06:23
  • @Kris I know it's very simple and I can't believe that it didn't pop out of my brains, but there are people on this level who are helped by this answer. I don't think there is written in the rules that it should be very hard. – WendiT May 06 '17 at 06:31

2 Answers2

2

Do not use AND simply separate it with different statement

if ($a == 1) {$b=2; $c=3;}
B. Desai
  • 16,414
  • 5
  • 26
  • 47
  • Duhhhhhh. Terrible I had to ask this question. Sometimes my brain is locked. O well, nothing wrong with easy answers. – WendiT May 06 '17 at 06:29
1

Your have a syntax problem there. But it's possible :

if ($a == 1) {
    $b = 2;
    $c = 3;
}
JazZ
  • 4,469
  • 2
  • 20
  • 40