2

I'm looking for solution to convert one dimensional array to multidimensional array. I have array:

array (size=10)
  'title' => string 'chart title' (length=11)
  'hAxis-title' => string 'hax title' (length=9)
  'hAxis-format' => string 'hax format' (length=10)
  'vAxis-title' => string 'vax title' (length=9)
  'vAxis-format' => string 'vax format' (length=10)
  'vAxis-gridlines-color' => string 'vax gridl color' (length=15)
  'vAxis-gridlines-count' => string '1' (length=1)
  'vAxis-gridlines-height-test' => string '2' (length=1)
  'height' => string '3' (length=1)
  'width' => string '4' (length=1)

and I need to convert it to:

array (size=5)
      'title' => string 'chart title' (length=11)
      'hAxis' => 
        array (size=2)
          'title' => string 'hax title' (length=9)
          'format' => string 'hax format' (length=10)
      'vAxis' => 
        array (size=2)
          'title' => string 'vax title' (length=9)
          'format' => string 'vax format' (length=10)
          'gridlines' =>
            array (size=3)
              'color' =>  string 'vax gridl color' (length=15)
              'count' =>  string '1' (length=1)
              'height' =>
                array (size=1)
                  'test' => string '2' (length=1)
      'height' => string '3' (length=1)
      'width' => string '4' (length=1)

I tried to use array functions, loops etc but only got to the point that I'm getting:

array (size=5)
      'title' => string 'chart title' (length=11)
      'hAxis' => 
        array (size=2)
          'title' => string 'hax title' (length=9)
          'format' => string 'hax format' (length=10)
      'vAxis' => 
        array (size=2)
          'title' => string 'vax title' (length=9)
          'format' => string 'vax format' (length=10)
      'height' => string '3' (length=1)
      'width' => string '4' (length=1)

Any ideas ? Please.

9
  • 1
    @JayBlanchard really not.. Only the titles of the questions are the same. Commented Jun 3, 2015 at 12:26
  • Unfortunately @Crembo a search reveals there are dozens of answers on SO for performing the transformation. Commented Jun 3, 2015 at 12:28
  • 1
    @Strabek I do not agree that this is a double. Commented Jun 3, 2015 at 12:46
  • 1
    @splash58 maybe it's not exactly the same, but solution works for me Commented Jun 3, 2015 at 12:48
  • 1
    Look there eval.in/374942 . Maybe it more interesting Commented Jun 3, 2015 at 12:49

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.