The following code take an array containing a series of row from a mySQL JOIN and restructures them into a multidimensional array.
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);
}
The output array printed is below.
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
)
)
)
The problem is that I want to list the theme arrays by ID number so that fields that repeat write over each other inserting only fields that are not already defined.
I am looking for the outcome to be this:
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
)
)
)
How can this be achieved?