搜索数组用于匹配的字符串 [英] Search an array for a matching string

查看:88
本文介绍了搜索数组用于匹配的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要寻找而去检查是否存在字符串作为在阵列中的价值是可能的,我怎么会用PHP做呢?

I am looking for away to check if a string exists as an array value in an array is that possible and how would I do it with PHP?

推荐答案

如果你只是想知道,如果它存在,使用的 in_array(),例如:

If you simply want to know if it exists, use in_array(), e.g.:

$exists = in_array("needle", $haystack);

如果你想知道它的相应的键,使用 array_search(),例如:

If you want to know its corresponding key, use array_search(), e.g.:

$key = array_search("needle", $haystack);
// will return key for found value, or FALSE if not found

这篇关于搜索数组用于匹配的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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