Laravel: 如何将查询结果中的数组分离成变量?

Laravel: How to separate array from query result into variables?

我有这样的东西:

return Model::get()->pluck('count','column');

Result:
{"ABC":1,"DEF":3,"GHI":1,"JKL":2}

如何将'column'和'count'分开成变量?

$column = ["ABC","DEF","GHI","JKL"];

$count = [1,3,1,2];

使用原生PHP功能; array_keysarray_values.

$result = Model::get()->pluck('count', 'column');
$column = array_keys($result);
$count = array_values($result);

有关详细信息,请阅读以下链接;

https://www.php.net/manual/en/function.array-keys.php

https://www.php.net/manual/en/function.array-values.php

试试这个

$array = Model::pluck('count','column')->toArray();
$key   = array_keys($array);
$values = array_values($array);