Wow, now THAT'S a confusing array! But everything is doable, right? It's just a matter of what you're willing to try. :)
I think you need to create a new array that fits the listing purpose, then iterate through that for the list (The huge complex array will remain intact for whatever else it's used for). Consider this:
<?php
if ( !empty( $array ) ) {
//Create the new array $uls[id][color]['link'/'link-title']
foreach ( $array['page']['colours']['subpage'] as $color => $subpage ) {
$uls[$subpage['aside']['collapse']['id']][$color]['link'] = $subpage['aside']['link'];
$uls[$subpage['aside']['collapse']['id']][$color]['link-title'] = $subpage['aside']['link-title'];
}
}
if ( !empty( $uls ) ) {
echo '<aside id="sidebar">';
echo '<ul class="menu">';
//iterate through the new $uls array
foreach($uls as $id => $color) {
//for each id, we create a ul, then iterate through that id's array
echo '<li><ul id="' . $id . '">';
foreach($color as $link_array) {
//echo the list item for each link in the id
$active = ($currentPageLink === $link_array['link']) ? 'active' : '';
echo '<li><a href="' . $link_array['link'] . '" class="' . $active . '">' . $link_array['link-title'] . '</a></li>';
}
echo '</ul></li>';
}
echo '</ul>';
echo '</aside>';
}
?>
One thing I didn't add was the data-collapse link. I wasn't sure exactly what you were going for there. That shouldn't be too hard to stick in there though.