Convert from object to array

So I am getting result like this:

[{"modelone_year":2021,"modeltwo_year":2019}]  

How do I need to convert this to this?

[2021,2019]

This is from where I get result:

 $years = Invoice::query()
          ->join('expenses', 'expenses.company_id','=', 'invoices.company_id')
          ->groupBy('modelone_year')
          ->groupBy('modeltwo_year')
          ->get();

Solution 1:

You got a collection and have to convert to an array. then you can use array_value (https://www.php.net/manual/de/function.array-values.php). You will receive all values as an array: Like that:

<?php
$collection = '[{"modelone_year":2021,"modeltwo_year":2019}]';
$arr = $collection->toArray();

$val = array_values($arr[0]);

print_r($val);
// output [2021,2019]