2

The following results in $c getting 'a', when intuition says it should get tie. What is going on here?

$a = 3;
$b = 3;
$c = $a === $b ? 'tie' : $a > $b ? 'a' : 'b';
var_dump($c); // shows a
Majid Fouladpour
  • 29,356
  • 21
  • 76
  • 127

2 Answers2

2

Yo need to put the code between ()

    $a = 3;
    $b = 3;
    $c = ($a === $b ? 'tie' : ($a > $b ? 'a' : 'b'));
Nerea
  • 2,107
  • 2
  • 15
  • 14
1
$a = 3;
$b = 3;
$c = ($a === $b) ? 'tie' : (($a > $b) ? 'a' : 'b');
var_dump($c);