-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];

2 Answers2

1

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;

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

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

cednore
  • 874
  • 4
  • 20
1

try this

$array = Model::pluck('count','column')->toArray();
$key   = array_keys($array);
$values = array_values($array);
Rushikesh Ganesh
  • 290
  • 2
  • 16