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
  • 27,709
  • 19
  • 72
  • 126

2 Answers2

2

Yo need to put the code between ()

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