查找PHP数组兄弟键的值 [英] Find value of sibling key in php array
本文介绍了查找PHP数组兄弟键的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在PHP中的数组,这里是一个片段:
阵列
(
[0] =>排列
(
[ID] => 202
[名] => GXP俱乐部 - 寓言
)[1] =>排列
(
[ID] => 204
[名] => GXP俱乐部 - 格雷
)
)
我知道(从GET)什么是ID(202)。我想,显示效果
对显示结果(其中$位置[?] [ID] = $ _GET ['身份证'] {回声$位置[?] [名]})
- 如果你会原谅我使用伪code的
不知道什么功能是最好的,或者如果我需要循环整个数组发现。谢谢你。
编辑:为进一步澄清。我需要学习的[名]指定的[ID]
解决方案
的foreach($ $作为编曲的位置){
如果($改编['身份证'] == $ _GET ['身份证']){
回声$改编['名'];
打破;
}
}
这是应该做的伎俩。
I have an array in PHP, here is a snippet:
Array
(
[0] => Array
(
[id] => 202
[name] => GXP Club - Fable
)
[1] => Array
(
[id] => 204
[name] => GXP Club - Gray
)
)
What I know (from a GET) is the ID (202). What I would like to display is
"Showing results for "
( where $locations[?][id] = $_GET['id'] { echo $locations[?][name] } )
- if you will pardon my use of pseudo code.
Not sure what function is best or if I need to loop over the whole array to find that. Thanks.
Edit: for further clarification. I need to learn the [name] given the [id]
解决方案
foreach( $locations as $arr ) {
if($arr['id'] == $_GET['id']) {
echo $arr['name'];
break;
}
}
That should do the trick.
这篇关于查找PHP数组兄弟键的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文