0

I have this array:

 {
  "text": {
       "3": "asdsadad",
       "4": "123123"
  },
  "textarea": {
       "5": "45655656",
       "6": "89879879789"
  },
  "file": {
       "2": {}
  }
 }

I'm trying to achieve this:

   {
    "3": "asdsadad",
    "4": "123123"
    "5": "45655656",
    "6": "89879879789"
    "2": {}
   }
halfer
  • 19,824
  • 17
  • 99
  • 186
  • 1
    The duplicate answer is not really a Laravel answer, which **does** exist: https://laravel.com/docs/5.4/helpers#method-array-flatten – online Thomas Jul 28 '17 at 22:03
  • @ThomasMoors although the `array_flatten` function does not preserve keys. – fubar Jul 29 '17 at 00:52
  • Use the power of collections! if $arr is your array as noted above: *collect($arr)->mapWithKeys(function ($item) { return collect($item)->each(function($value, $key) { return [$key => $value]; });* })->toArray(); – Rob Fonseca Jul 29 '17 at 02:19

0 Answers0