I have something like this:
return Model::get()->pluck('count','column');
Result:
{"ABC":1,"DEF":3,"GHI":1,"JKL":2}
How to separate the 'column' and 'count' into variables?
$column = ["ABC","DEF","GHI","JKL"];
$count = [1,3,1,2];
I have something like this:
return Model::get()->pluck('count','column');
Result:
{"ABC":1,"DEF":3,"GHI":1,"JKL":2}
How to separate the 'column' and 'count' into variables?
$column = ["ABC","DEF","GHI","JKL"];
$count = [1,3,1,2];
Use native PHP functions; array_keys
and array_values
.
$result = Model::get()->pluck('count', 'column');
$column = array_keys($result);
$count = array_values($result);
For more details, read the below links;
try this
$array = Model::pluck('count','column')->toArray();
$key = array_keys($array);
$values = array_values($array);