通过匹配字符从json文件获取数组

时间:2019-06-22 15:49:17

标签: php json laravel

我是Laravel的新手,我有一个导入到控制器的json文件.Json格式如下:

{
"China": ["Guangzhou", "Fuzhou", "Beijing", "Baotou"],
"Japan": ["Tokyo", "Hiroshima", "Saitama", "Nihon'odori"],
"Thailand": ["Bangkok", "Chumphon", "Kathu", "Phang Khon"]
}

现在,我想匹配国家/地区并获取整个相应数组并将其存储在变量中。 我想找到中国,并获取只有中国的整个阵列

这是我在控制器中的方法

public function cities(){
    $country = 'China';
    $path = storage_path()."/countriesToCities.json";
    $json = json_decode(file_get_contents($path), true); 

    return view('tasks.create_task')->with('result',$result);
}

0 个答案:

没有答案