PHP二维数组搜索返回数组

 1 $ar = array(
 2     2 => array(
 3         'catid' => 2,
 4         'catdir' => 'notice',
 5     ),
 6     5 => array(
 7         'catid' => 5,
 8         'catdir' => 'subject',
 9     ),
10     6=> array(
11         'catid' => 6,
12         'catdir' => 'news'
13     ),
14 );
15  
16 $catid = 5;
17 $r = array_filter($ar, function($t) use ($catid) { return $t['catid'] == $catid; });
18 print_r($r);

结果:

1 Array
2 (
3     [5] => Array
4         (
5             [catid] => 5
6             [catdir] => subject
7         )
8  
9 )

 

posted @ 2017-11-14 11:22  原来是个帅小伙  阅读(467)  评论(0编辑  收藏  举报