$nav = array(
"title1" => "url1",
"title2" => array(
"sub-page1" => "url1",
"sub-page2" => "url2"
),
"title3" => array(
"sub-page1" => "url1",
"sub-page2" => "url2"
),
"title4" => array(
"sub-title1" => array(
"sub-sub-page1" => "url1",
"sub-sub-page2" => "url2",
),
"sub-title2" => array(
"sub-sub-page1" => "url1",
"sub-sub-page2" => "url2",
)
),
"title5" => "url1",
"title6" => "url1"
);
Actually, the array looks more like that.
I've tried using foreach, and multiple for loops, but the code just doesn't seem to work : /
Here is some of the code I've been working with:
public function __construct( ) {
/*foreach( $include as $item ) {
$link = $this->pages[$item];
if( is_array( $link ) ) {
echo '<li><a href="' . reset( $link ) . '" title="' . $item . '">' . $item . '</a></li>' . "\r\n";
} else {
echo '<li><a href="' . $link . '" title="' . $item . '">' . $item . '</a></li>' . "\r\n";
}
}*/
/*
if ( empty( $array ) ) return '';
$output = '<ul>';
foreach ( $array as $key => $subArray ) {
$output .= '<li>' . $key . makeList($subArray) . '</li>';
}
$output .= '</ul>';
return $output;
*/
}
//Make a list from an array
public function makeList( $pages ) {
//Base case: an empty array produces no list
if( empty( $array ) ) return '';
//Recursive Step: make a list with child lists
$output = '<ul>';
foreach( $array as $key => $subArray ) {
$output .= '<li>' . $key . makeList( $subArray ) . '</li>';
}
$output .= '</ul>';
return $output;
}
I'm just jumping back into this project, so I'm not 100% sure where it left off.