PHP数组获取特定值位置 [英] php array get positions of the specific value
本文介绍了PHP数组获取特定值位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个数组,我要得到一个特定的值的位置
I have one array and I want to get the positions of one specific value
例如:
$my_array = array(0,2,5,3,7,4,5,2,1,6,9);
我搜索的第5号的的位置的第5号的数组为(的 2 的和的 6 )
My search is Number 5 the positions of Number 5 in array was (2 and 6)
如果我称之为 array_search
函数,始终返回数组女巫第一位置的 2 的
If i call the array_search
function, always returns the first position in array witch is 2.
反正是有得到两矿特定值更岗位?
Is there anyway to get the two ore more positions of specific value?
推荐答案
使用 array_keys 与可选的搜索参数,应该返回所有的键。
Use array_keys with the optional search parameter, that should return all of the keys.
$匹配= array_keys($ my_array,5);
这篇关于PHP数组获取特定值位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文