php 二维数组查找数组下标
比如这么一个数组:Array([0]=>Array([id]=>1[metal]=>19[wood]=>6[fire]=>40[water]=>40[earth]=>40...
比如这么一个数组:
Array
(
[0] => Array
(
[id] => 1
[metal] => 19
[wood] => 6
[fire] => 40
[water] => 40
[earth] => 40
[uid] => 1
)
[1] => Array
(
[id] => 2
[metal] => 52
[wood] => 58
[fire] => 40
[water] => 40
[earth] => 40
[uid] => 2
)
[2] => Array
(
[id] => 3
[metal] => 57
[wood] => 44
[fire] => 40
[water] => 40
[earth] => 42
[uid] => 3
)
[3] => Array
(
[id] => 4
[metal] => 40
[wood] => 43
[fire] => 40
[water] => 40
[earth] => 41
[uid] => 4
)
[4] => Array
(
[id] => 5
[metal] => 40
[wood] => 40
[fire] => 40
[water] => 40
[earth] => 40
[uid] => 5
)
);
我想要同过可以获取的uid的值,比如是2。从而获得其在这整个大数组中得下标[1]。
这个逻辑应该如何实现呢,本人是菜鸟,万分感激,在线等!!!!!!!!!!!!!!!!!!!!!!!!! 展开
Array
(
[0] => Array
(
[id] => 1
[metal] => 19
[wood] => 6
[fire] => 40
[water] => 40
[earth] => 40
[uid] => 1
)
[1] => Array
(
[id] => 2
[metal] => 52
[wood] => 58
[fire] => 40
[water] => 40
[earth] => 40
[uid] => 2
)
[2] => Array
(
[id] => 3
[metal] => 57
[wood] => 44
[fire] => 40
[water] => 40
[earth] => 42
[uid] => 3
)
[3] => Array
(
[id] => 4
[metal] => 40
[wood] => 43
[fire] => 40
[water] => 40
[earth] => 41
[uid] => 4
)
[4] => Array
(
[id] => 5
[metal] => 40
[wood] => 40
[fire] => 40
[water] => 40
[earth] => 40
[uid] => 5
)
);
我想要同过可以获取的uid的值,比如是2。从而获得其在这整个大数组中得下标[1]。
这个逻辑应该如何实现呢,本人是菜鸟,万分感激,在线等!!!!!!!!!!!!!!!!!!!!!!!!! 展开
2个回答
展开全部
很简单,遍历一遍数组就可以了
foreach($arr as $k=>$v){
if($v['uid']==2){
return $k;
}
}
这个$k就是
foreach($arr as $k=>$v){
if($v['uid']==2){
return $k;
}
}
这个$k就是
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询