PHP中的double not(!!)运算符 [英] Double not (!!) operator in PHP

查看:103
本文介绍了PHP中的double not(!!)运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

双重 not 运算符在PHP中做什么?

What does the double not operator do in PHP?

例如:

return !! $row;

上面的代码会做什么?

推荐答案

它不是"double not运算符",而是两次应用了 not 运算符.右边的!将导致一个布尔值,无论操作数是什么.然后左边的!将取反该布尔值.

It's not the "double not operator", it's the not operator applied twice. The right ! will result in a boolean, regardless of the operand. Then the left ! will negate that boolean.

这意味着对于任何真值(非零,非空字符串和数组等),您将获得布尔值TRUE,对于任何假值(0、0.0,NULL,空字符串或空数组),您将获得布尔值FALSE.

This means that for any true value (numbers other than zero, non-empty strings and arrays, etc.) you will get the boolean value TRUE, and for any false value (0, 0.0, NULL, empty strings or empty arrays) you will get the boolean value FALSE.

在功能上等同于强制转换为boolean:

It is functionally equivalent to a cast to boolean:

return (bool)$row;

这篇关于PHP中的double not(!!)运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆