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_keys
和 array_values
.
$result = Model::get()->pluck('count', 'column');
$column = array_keys($result);
$count = array_values($result);
有关详细信息,请阅读以下链接;
试试这个
$array = Model::pluck('count','column')->toArray();
$key = array_keys($array);
$values = array_values($array);
我有这样的东西:
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_keys
和 array_values
.
$result = Model::get()->pluck('count', 'column');
$column = array_keys($result);
$count = array_values($result);
有关详细信息,请阅读以下链接;
试试这个
$array = Model::pluck('count','column')->toArray();
$key = array_keys($array);
$values = array_values($array);