M
M
Mazino2019-04-02 16:36:34
Laravel
Mazino, 2019-04-02 16:36:34

How to group array data into flat structure with key binding?

There is such

collection:
Collection {#348 ▼
  #items: array:3 [▼
    2017 => Collection {#350 ▼
      #items: array:3 [▼
        4 => Collection {#347 ▼
          #items: array:2 [▼
            0 => Collection {#327 ▼
              #items: array:4 [▼
                0 => "90"
                1 => "0"
                2 => "2017-11-01 00:00:00"
                3 => "2017-11-30 23:59:59"
              ]
            }
            1 => Collection {#351 ▼
              #items: array:4 [▼
                0 => "90"
                1 => "0"
                2 => "2017-12-01 00:00:00"
                3 => "2017-12-31 23:59:59"
              ]
            }
          ]
        }
      ]
    }

It is necessary to prepare the data for output in DataTables, for this you need to convert all lower-level values, for example, with key 0, to a flat array.
Collection {#348 ▼
  #items: array:3 [▼
    2017 => Collection {#350 ▼
      #items: array:3 [▼
        4 => Collection {#347 ▼
          #items: array:4 [▼
            0 => Collection {#327 ▼
              #items: array:2 [▼
                0 => "90"
                1 => "90"                
              ]
             }
             1 => Collection {#351 ▼
              #items: array:2 [▼
                0 => "0"
                1 => "0"
               ]
              }
              2 => Collection {#352
              #items: array:2 [
                0 => "2017-11-01 00:00:00"
                1 => "2017-12-01 00:00:00"
               ]
              }
              3 => Collection {#351 ▼
              #items: array:2 [▼
               0 => "2017-11-30 23:59:59"
               1 => "2017-12-31 23:59:59"
              ]
             }
            ]
           }
          ]
        }
      ]
    }

How to do it?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question