It is just two !
boolean not operators sitting next to each other.
The reason to use this idiom is to make sure that you receive a 1
or a 0
. Actually it returns an empty string which numifys to 0. It's usually only used in numeric, or boolean context though.
You will often see this in Code Golf competitions, because it is shorter than using the ternary ? :
operator with 1
and 0
($test ? 1 : 0
).
!! undef == 0
!! 0 == 0
!! 1 == 1
!! $obj ? == 1
!! 100 == 1
undef ? 1 : 0 == 0
0 ? 1 : 0 == 0
1 ? 1 : 0 == 1
$obj ? 1 : 0 == 1
100 ? 1 : 0 == 1
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…