0

如何使用 set combine 制作关联数组?

我已经设法通过合并来创建一个带有索引的数组,我只是 foreach troughout 结果并将所有 3 个数组合并为一个,但这不是关联数组,我可以用组合来做吗?

例子 :

Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [Year] => 2003
                    [Month] => June
                    [MyCount] => 1
                )

            [MyData1] => Array
                (
                    [type] => 10
                )

            [MyData2] => Array
                (
                    [status] => 1
                )

        )

    [1] => Array
        (

            [0] => Array
                (
                    [Year] => 2003
                    [Month] => June
                    [MyCount] => 32
                )

            [MyData1] => Array
                (
                    [type] => 7
                )

            [MyData2] => Array
                (
                    [status] => 21
                )

        )

)

我怎样才能让它变成这样:

 Array
    (
        [0] => Array
            (
                ['SomeName'] => Array
                    (
                        [Year] => 2003
                        [Month] => June
                        [MyCount] => 1
                        [type] => 10
                        [status] => 1
                    )

            )

        [1] => Array
            (

                ['SomeName'] => Array
                    (
                        [Year] => 2003
                        [Month] => June
                        [MyCount] => 32
                        [type] => 7
                        [status] => 21
                    )

            )

    )
4

1 回答 1

3

试试这个

$a_final =array();
foreach($final as $data)
{
  $a_final[]['SomeName'] = array('Year' => $data[0]['year'], 
                                 'Month' => $data[0]['Month'], 
                                 'MyCount' => $data[0]['MyCount'], 
                                 'type' => $data['MyData1']['type'], 
                                 'status' => $data['MyData2']['status']);
}
于 2012-06-11T17:44:33.733 回答