Skip to content
Advertisement

Using ternary operator in echo?

How come I can use echo like this:

JavaScript

But can’t use it like this

JavaScript

Advertisement

Answer

The ?? Operator in PHP is the Null Coalescing Operator:

JavaScript

Since in this case expr1 is false but is set, this expression returns Boolean false.

Compare:

JavaScript

Echo does not output when passed Boolean false.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement