PHP,检查一个值是否在数组中
这可能很简单,但我无法让它在 php 中工作。
我需要的是以下内容(书面解释)
if ( 11 is in array(1,3,4,6,7,8,9,11,34,45,56,77) ) : return true;
非常感谢:)
This is probably very easy but I cannot get it to work in php.
What I need is the following (written explanatory)
if ( 11 is in array(1,3,4,6,7,8,9,11,34,45,56,77) ) : return true;
Thanks a lot :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
$answer
是一个布尔值。$answer
is a boolean.尝试:
参见: PHP 的 in_array() 其方法签名为:
$needle
是您要查找的值,在本例中11
,$haystack
是您要搜索的数组。如果您为最后一个参数传递true
,则您是在告诉 PHP 仅使用您在$needle
中指定的类型。例如,如果您传递
"11"
并将$strict
设置为true
,则它将找不到11
。Try:
See: PHP's in_array() which has a method signature of:
The
$needle
being the value you are looking for, in this instance11
and the$haystack
being the array that you want to search. If you passtrue
for the final parameter, you are telling PHP to only use the type that you've specified in$needle
.For instance, if you pass
"11"
and set$strict
totrue
, it would not find11
.这样就可以了!
This'll do it!