There are a number of different inline conditionals I use when working with PHP (i.e. ternary conditionals and the null coalescing operator). As a reminder of how some of these common inline conditionals work, I put together this table for reference.
$value |
$value ? $value : 13 $value ?: 13 |
isset( $value ) ? $value : 13 $value ?? 13 |
! empty( $value ) ? $value : 13 |
---|---|---|---|
0 (zero) |
13 |
0 |
13 |
false |
13 |
false |
13 |
unassigned | 13 throws “undefined variable” notice |
13 |
13 |
null |
13 |
13 |
13 |
'sal' |
'sal' |
'sal' |
'sal' |
'' |
13 |
'' |
13 |
Leave a Reply