【问题标题】:CakePHP make from result with set combine associative arrayCakePHP 从结果与集合组合关联数组
【发布时间】:2012-06-11 17:06:07
【问题描述】:

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

我已经通过合并来创建一个带索引的数组,我刚刚获得了 troughout 结果并将所有 3 个数组合并为一个,但这不是关联数组,我可以使用 combine 吗?

例子:

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
                    )

            )

    )

【问题讨论】:

    标签: php cakephp cakephp-1.3 associative-array


    【解决方案1】:

    试试这个

    $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']);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-03
      • 1970-01-01
      • 1970-01-01
      • 2013-03-09
      • 1970-01-01
      • 2016-02-20
      • 2013-07-10
      • 1970-01-01
      相关资源
      最近更新 更多