到目前为止,我有三个数组,它们像这样从数据库返回值(经过多次格式化)
[0]=>array(
[0]=>'Apr', [1]=> 1),
[1]=>array(
[0]=>'May', [1]=>2),
[2]=>array(
[0]=>'Jun', [1]=>23)
具有相似值的第二个数组:
[0]=>array(
[0]=>'Mar', [1]=>22),
[1]=>array(
[0]=>'Apr', [1]=> 1),
[2]=>array(
[0]=>'May', [1]=>2),
[3]=>array(
[0]=>'Jun', [1]=>25)
第三个:
[0]=>array(
[0]=>'Jan', [1]=>50),
[1]=>array(
[0]=>'Feb', [1]=> 20),
[2]=>array(
[0]=>'Mar', [1]=>16),
[3]=>array(
[0]=>'Jun', [1]=>5)
这就是我试图使它们成为的方式:
[0]=>array(
[0]=>'Month', [1]=>'Calc1', [2]=>'Calc2', [3]=>'Calc3'),
[1]=>array(
[0]=>'Jan', [1]=>0, [2]=>0, [3]=>50),
[2]=>array(
[0]=>'Feb', [1]=>0, [2]=>0, [3]=>20),
[3]=>array(
[0]=>'Mar', [1]=>0, [2]=>22, [3]=>16),
[4]=>array(
[0]=>'Apr', [1]=>1, [2]=>1, [3]=>0),
[5]=>array(
[0]=>'May', [1]=>2, [2]=>2, [3]=>0),
[6]=>array(
[0]=>'Jun', [1]=>23, [2]=>25, [3]=>5)
请注意“0”是如何填充到不包含值的地方的。老实说,这是我遇到过的最复杂的数组问题,原因是遍历数组很困难。我特别需要数组是这种结构,因为我需要将它发送到 Google Visualization Area Chart。
如果您发现任何有关此问题的建议,请发布。
提前非常感谢你:)
@DevZer0:这是我得到的输出(带有我的真实数据)。请注意月份如何重复:
array(
[0] =>
array(
[0] =>'Month'
[1] =>'Calc1'
[2] =>'Calc2'
[3] =>'Calc3'
)
[1] =>
array(
[0] =>'Apr'
[1] =>1
[2] =>0
[3] =>0
)
[2] =>
array(
[0] =>'Jun'
[1] =>9
[2] =>0
[3] =>0
)
[3] =>
array(
[0] =>'Apr'
[1] =>0
[2] =>1
[3] =>0
)
[4] =>
array(
[0] =>'May'
[1] =>0
[2] =>2
[3] =>0
)
[5] =>
array(
[0] =>'Jun'
[1] =>0
[2] =>23
[3] =>0
)
[6] =>
array(
[0] =>'Apr'
[1] =>0
[2] =>0
[3] =>1
)
[7] =>
array(
[0] =>'May'
[1] =>0
[2] =>0
[3] =>3
)
[8] =>
array(
[0] =>'Jun'
[1] =>0
[2] =>0
[3] =>27
)
)
我希望它们以这种格式连接:
array(
[0] =>
array(
[0] =>'Month'
[1] =>'Calc1'
[2] =>'Calc2'
[3] =>'Calc3'
)
[1] =>
array(
[0] =>'Apr'
[1] =>1
[2] =>1
[3] =>1
)
[2] =>
array(
[0] =>'May'
[1] =>0
[2] =>2
[3] =>3
)
[3] =>
array(
[0] =>'Jun'
[1] =>9
[2] =>23
[3] =>27
)
)
有没有办法做到这一点?再次感谢你:)