php 多维数组查询 ,根据一个值检索指定数组,怎么实现?
根据slug=mobile这样检索!Array([0]=>stdClassObject([id]=>1[name]=>手机[slug]=>mobile)[1]=>stdC...
根据 slug = mobile 这样检索!
Array
(
[0] => stdClass Object
(
[id] => 1
[name] => 手机
[slug] => mobile
)
[1] => stdClass Object
(
[id] => 2
[name] => 电视
[slug] => tv
)
[2] => stdClass Object
(
[id] => 3
[name] => 所有
[slug] => all
)
[3] => stdClass Object
(
[term_id] => 4
[name] => 游戏机
[slug] => game
)
) 展开
Array
(
[0] => stdClass Object
(
[id] => 1
[name] => 手机
[slug] => mobile
)
[1] => stdClass Object
(
[id] => 2
[name] => 电视
[slug] => tv
)
[2] => stdClass Object
(
[id] => 3
[name] => 所有
[slug] => all
)
[3] => stdClass Object
(
[term_id] => 4
[name] => 游戏机
[slug] => game
)
) 展开
展开全部
//换成你的二维数组
$array = array(
array('key'=>'b','val'=>2),
array('key'=>'c','val'=>3),
array('key'=>'d','val'=>4),
array('key'=>'e','val'=>5),
);
$result = array_filter($array , 'filter');
print_r($result);
function filter($v){
//换成你要的条件
return $v['key'] == 'c';
}
追问
array_filter($array , filter('e'));
改成这样怎么做?
追答
不可以, 你可以用全局变量来实现你的这个需求
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询