以下代码从 mySQL JOIN 中获取一个包含一系列行的数组,并将它们重组为一个多维数组。
foreach($content as $cont){
if(!$pagecontent){
$pagecontent = $cont;
$pagecontent['theme'] = array();
}
$themearray = array(
'themeID' => $cont['themeID'],
'theme_type' => $cont['theme_type'],
'theme_file' => $cont['theme_file'],
'theme_default' => $cont['theme_default'],
'theme_title' => $cont['theme_title'],
$cont['meta_field'] => $cont['meta_value']
);
array_push($pagecontent['theme'], $themearray);
}
打印的输出数组如下。
Array
(
[contentID] => 9
[type] => operations
[title] => CTK Partners
[parent] => 8
[theme] => Array
(
[0] => Array
(
[themeID] => 2
[theme_type] => general
[theme_file] => logo
[theme_default] => 1
[theme_title] => CTT Group
[src] => uploads/img/clogo.png
)
[1] => Array
(
[themeID] => 2
[theme_type] => general
[theme_file] => logo
[theme_default] => 1
[theme_title] => CTT Group
[title] => CTT Industries
)
[2] => Array
(
[themeID] => 5
[theme_type] => general
[theme_file] => logo
[theme_default] => 0
[theme_title] => CTT Logo 2
[src] => uploads/img/cttlogo2.png
)
[3] => Array
(
[themeID] => 5
[theme_type] => general
[theme_file] => logo
[theme_default] => 0
[theme_title] => CTT Logo 2
[title] => CTF Associates
)
)
)
问题是我想按 ID 号列出主题数组,以便重复的字段相互覆盖,仅插入尚未定义的字段。
我正在寻找结果是这样的:
Array
(
[contentID] => 9
[type] => operations
[title] => CTK Partners
[parent] => 8
[theme] => Array
(
[themeID2] => Array
(
[themeID] => 2
[theme_type] => general
[theme_file] => logo
[theme_default] => 1
[theme_title] => CTT Group
[src] => uploads/img/clogo.png
[title] => CTT Industries
)
[themeID5] => Array
(
[themeID] => 5
[theme_type] => general
[theme_file] => logo
[theme_default] => 0
[theme_title] => CTT Logo 2
[src] => uploads/img/cttlogo2.png
[title] => CTF Associates
)
)
)
如何做到这一点?