PHP在二维数组中根据键值查找
PHP在二维数组中根据键值查找$ar = array(
2 => array(
'catid' => 2,
'catdir' => 'notice',
),
5 => array(
'catid' => 5,
'catdir' => 'subject',
),
6=> array(
'catid' => 6,
'catdir' => 'news'
),
);
$catid = 5;
$r = array_filter($ar, function($t) use ($catid) { return $t['catid'] == $catid; });
$r = reset($r);
print_r($r);
效率上比遍历2次快的多(PHP>=5.4)
页:
[1]