Php 要合并的json字段的内容-Laravel应用程序
我需要一个唯一的关键字列表。这是查询Php 要合并的json字段的内容-Laravel应用程序,php,json,laravel-5.4,Php,Json,Laravel 5.4,我需要一个唯一的关键字列表。这是查询 $array['keywords'] = DB::table('job_posts') ->pluck('keywords')->toArray(); 在my job_posts表中,关键字列是一个json条目[laravel cast json] 对于记录1,关键字字段值为 ["jquery","html","css","js"] ["jquery","html","scss"] 对于记录1,关键字字段值为
$array['keywords'] = DB::table('job_posts')
->pluck('keywords')->toArray();
在my job_posts表中,关键字列是一个json条目[laravel cast json]
对于记录1,关键字字段值为
["jquery","html","css","js"]
["jquery","html","scss"]
对于记录1,关键字字段值为
["jquery","html","css","js"]
["jquery","html","scss"]
我需要这样的阵列
array('jquery','html','css','js','scss')
为了给选择框()提供选项,Laravel有一些很酷的数组,你可以使用 例如:
$test = [
['a', 'b', 'c', 'd'],
['b', 'c', 'd', 'e']
];
$flattened = array_flatten($test);
$unique = array_unique($flattened);
dd($unique);
将输出:
array:5 [▼
0 => "a"
1 => "b"
2 => "c"
3 => "d"
7 => "e"
]
更改了DB::table('job_posts')->Pull('keywords')->toArray();tojobPost::pull('keywords')->toArray();[转换为json]。然后应用你的方法。它起作用了。谢谢你。。。