PHP 中的 Double not (!!) 运算符
phpserver side programmingprogramming更新于 2025/11/19 17:46:00
在 Double not 运算符 (!!) 中,第一个 not 即 ! 用于对值取反,而第二个 not 即 ! 再次取反。要在 PHP 中实现 Double not 运算符,代码如下−
示例
<?php $str = "0.1"; echo "Value = $str"; $res = !!$str; echo "
Double Negated Value = $res"; ?>
输出
这将产生以下输出−
Value = 0.1 Double Negated Value = 1
示例
现在让我们看另一个例子 −
<?php $str = "100.56"; echo "String = $str"; $num = floatval($str); echo "
Number (Converted from String) = $num"; $res = !!$num; echo "
Double Negated Value = $res"; ?>
输出
这将产生以下输出−
String = 100.56 Number (Converted from String) = 100.56 Double Negated Value = 1

