在php数组中查找兄弟键的值 [英] Find value of sibling key in php array
本文介绍了在php数组中查找兄弟键的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 PHP 中有一个数组,这是一个片段:
I have an array in PHP, here is a snippet:
$locations = array(
array(
"id" => 202,
"name" => "GXP Club - Fable"
),
array (
"id" => 204,
"name" => "GXP Club - Gray"
)
);
我知道(从 GET)是 ID (202).我想显示的是显示结果"( where $locations[?][id] = $_GET['id'] { echo $locations[?][name] } )
- 请原谅我使用伪代码.
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.
进一步澄清.我需要学习给定 [id] 的 [name]
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;
}
}
这应该可以解决问题.
这篇关于在php数组中查找兄弟键的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文