简体   繁体   English

无法在PHP in_array中搜索数组是否存在多个指针

[英]Can't search an array in PHP in_array for the presence of multiple needles

When giving PHP in_array an array of values I want to search for, it does not work. 当给PHP in_array一个我想搜索的值数组时,它不起作用。 Although the documentation specifies that you can give a mixed needle. 尽管文档指定可以mixed

So basically I want to test for the presence of multiple terms as the value of an array - is there a reason this is not working, and can anyone suggest another way of doing this? 因此,基本上我想测试是否存在多个术语作为数组的值-是否有理由不起作用,有人可以建议另一种方法吗?

For something like searching an array $haystack for multiple $needles that are all strings or numbers, you can use array_intersect($array1, $array2, ...) 对于类似在数组$ haystack中搜索多个都是字符串或数字的$ needles的操作,可以使用array_intersect($array1, $array2, ...)

http://php.net/manual/en/function.array-intersect.php http://php.net/manual/en/function.array-intersect.php

It should work for mixed types also. 它也应该适用于混合类型。

When the documentation says mixed it means it can accept multiple types, eg int , float , string . 当文档中说到mixed ,表示它可以接受多种类型,例如intfloatstring Though the docs should say exactly which types are valid. 尽管文档应该确切说明哪些类型有效。

mixed doesn't mean more than one needle, it refers to types. 混合不代表多于一根针,而是指类型。 It's documentation talk for more than one possible type. 这是有关多种可能类型的文档讨论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM