[英]Strange usage of in_array
I stumbled upon this code: 我偶然发现了以下代码:
in_array(($_GET['some_value']??-1),[])
and I'm having some trouble understanding it. 而且我在理解它时遇到了一些麻烦。 My questions are as follows:
我的问题如下:
??
??
operator mean in this context? in_array
do if haystack
is an empty array? haystack
是一个空数组, in_array
做什么? Again, seems like it would always return FALSE
but I'm new to PHP so I'd like confirmation on this. FALSE
但是我是PHP新手,所以我想对此进行确认。 That expression can be replaced with 该表达式可以替换为
false
calling in_array
with an empty array as the second argument will always return false
, so it doesn't matter whether $_GET['some_value']
exists, what it is if it exists, or whether or not it ends up getting replaced with negative one by the null coalescing operator. 以空数组作为第二个参数调用
in_array
始终将返回false
,因此$_GET['some_value']
存在,它是否存在,是否最终被负数替换都$_GET['some_value']
由空合并运算符。
You can't find anything in an empty array. 您无法在空数组中找到任何内容。 It's probably either a mistake or an attempt at obfuscation.
这可能是错误或者是混淆的尝试。
The double question mark IS in fact the null coalesce operator, new in PHP 7: http://php.net/manual/de/migration70.new-features.php 实际上,双重问号是null合并运算符,这是PHP 7中的新增功能: http : //php.net/manual/de/migration70.new-features.php
in_array() will return false if haystack is an empty array, in fact it will only return TRUE if the needle is found in haystack. 如果haystack是一个空数组,则in_array()将返回false,实际上,只有在haystack中找到该指针时,它才会返回TRUE。 Read the documentation here:
在此处阅读文档:
http://php.net/manual/de/function.in-array.php http://php.net/manual/de/function.in-array.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.