使用关键字过滤数据集

i have an list of fonts returned from the googlefontsapi

public function filterFont() {

    $key = $this->request('key');
    $url = "https://www.googleapis.com/webfonts/v1/webfonts?key=''";
    $result = json_decode(file_get_contents( $url ));
    $filterfont = array_filter($result, function($obj)
    {
        $data = $obj->font_name == $key;
        $view = view('ajax.fonts', true)->with('data', $data);
        $value=array(

                'view'=>$view
        );
        echo json_encode($value);

    });

}

now i want to filter the data according to a value how can i achieve this

Try this:

$key = 'sans-serif';
$url = "https://www.googleapis.com/webfonts/v1/webfonts?key=''";
$result = json_decode(file_get_contents( $url ), true);
$result = $result['items'];
$filterfont = array_filter($result, function($obj) use ($key)
{
    return $data = $obj['category'] == $key;
});
var_dump($filterfont);

This code filter the fonts by category, depending the $key you use