Home > Mobile >  Check for boolean and set variable value or default without using ELSE in Laravel 8 controller
Check for boolean and set variable value or default without using ELSE in Laravel 8 controller

Time:02-13

I need to calculate points based on boolean selections and I'd like to reduce the amount of code by eliminating the ELSE part of my statements.

Is there anyway to compress this statement down?

...
if ($this->track) { 
   $trackPTS = 20;
} else { 
   $trackPTS = 0;
}
...

CodePudding user response:

something like this:

$trackPTS = $this->track ? 20 : 0;

  • Related