PHP具有键和值的多维数据的一维数组

时间:2015-06-03 12:19:28

标签: php arrays multidimensional-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)

我需要将其转换为:

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)

我尝试使用数组函数,循环等,但只是达到了我的目的:

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)

有什么想法吗?请。

0 个答案:

没有答案