As lightweight if use only 1 option?

For example if $id is not false you need to show it.
We want to make sure
<?= !$id ?: 'id =' . Html::encode($id) ?>
but when $id === false is output unit, and in theory nothing should be displayed.
July 2nd 19 at 18:27
2 answers
July 2nd 19 at 18:29
Solution
This is not a "shorthand if". This is the ternary operator. The word itself means "the Trinity" since it consists of 3 parts: the condition, the first branch, the second branch. Displays 1 because !false => true => 1. So echo works in php.
July 2nd 19 at 18:31
Solution
<?= $id ? 'id =' . Html::encode($id) : "?>
That's the way?
In General, verify the php version :)
Yes, since you have to do, but the extra block with the empty string as the curve, I think - Kendrick_Schu commented on July 2nd 19 at 18:34
php7 - Kendrick_Schu commented on July 2nd 19 at 18:37

Find more questions by tags PHP