如何使用set combine创建关联数组?
我已经使用merge来管理一个带索引的数组,我刚刚结束了整个结果并将所有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
)
)
)
答案 0 :(得分: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']);
}