0

How can I make associative array with set combine?

I have manage with merge to to make an array with index, I have just foreach troughout result and merge all 3 arrays into one, but that is not associative array, can I do it with combine?

Example :

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
                )

        )

)

How can I make it to be like this :

 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
                    )

            )

    )

1 Answer 1

3

try this

$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']);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.