Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 要合并的json字段的内容-Laravel应用程序_Php_Json_Laravel 5.4 - Fatal编程技术网

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]。然后应用你的方法。它起作用了。谢谢你。。。