I have an array built from an eloquent query which looks like this:
[['ctry' => 'US', 'subs' => 10], ['ctry' => 'AU', 'subs' => 25], ....]
And I want to convert it to:
['US' => 10, 'AU' => 25, ...]
I have tried array_map, call_user_func_array, laravel's flatten without success. Thanks
A possible solution can be
<?php
$sample_array = [['ctry' => 'US', 'subs' => 10], ['ctry' => 'AU', 'subs' => 25]]; # more elements in the array
$result_array = [];
foreach ($sample_array as $key => $value) {
array_push($result_array, [$value['ctry'] => $value['subs']]);
}
print_r($result_array);