0

I have this code below using nested shorthand if:

$foo = new stdClass;
$foo->type = 'regular';
$foo->group_one = 1;
$foo->group_two = 2;

$group_id = $foo->type == 'regular' ? $foo->group_one : $foo->type == 'agent' ? $foo->group_two : null;

var_dump($group_id);

I expected the value to be 1. Why the value of $group_id is 2?

rodrigoum
  • 185
  • 8

0 Answers0