Reputation: 1310
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
)
)
)
Upvotes: 0
Views: 1286
Reputation: 8461
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']);
}
Upvotes: 3