The ternary operator is used to replace an if else statement with a single statement.
1 |
|
1 2 3 4 5 6 |
|
If the condition is true, return the result of expression 1, otherwise return the result of expression 2. void is not allowed in conditions or expressions.
The null coalescing operator is used to provide a non-null value when the variable is empty.
1 |
|
1 2 3 4 5 6 |
|
If the variable is empty, the result of the expression is returned.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
1 2 |
|
The above is the detailed content of In php, what is the difference between ternary operator and null coalescing operator?. For more information, please follow other related articles on the PHP Chinese website!