array_filter,匿名函数

时间:2021-01-28 16:30:23
    static function get_categoryII() {
return array(
array('id' => 1, 'c1id' => 1, 'name' => '1aaaa'),
array('id' => 2, 'c1id' => 1, 'name' => '1bbb'),
array('id' => 3, 'c1id' => 2, 'name' => '1bbbb'),
array('id' => 4, 'c1id' => 3, 'name' => '1cccccc'),
);
} function mytest() {
$res = self::get_categoryII();
$catid = 2;
$r = array_filter($res, function($t) use ($catid) {
return $t['c1id'] == $catid;
});
dump($r);
}