Jump to content

ThisIsPHP

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Everything posted by ThisIsPHP

  1. I'll play with it. Thank you for your help! If I run into anything else, I'll post back up here.
  2. Thanks!!! Not every title links to a page. Some will need to link to the first child page in the first sub section.
  3. $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.
  4. Hi PHP Freaks! Here is my problem. I want to have a PHP navigation system that uses Arrays to control it. $nav = array( "title1" => "url1", "title2" => array( "sub-page1" => "url1", "sub-page2" => "url2" ), "title3" => array( "sub-page1" => "url1", "sub-page2" => "url2" ), "title4" => array( "sub-page1" => "url1", "sub-page2" => "url2" ), "title5" => "url1", "title6" => "url1" ); $loc = basename($_SERVER["REQUEST_URI"]); What I'm trying to do, is if the $loc is a url in "title4" I want a ul/li printout of that array. Any help you could share with me would be MUCH appreciated. The printout should look like: <ul> <li>Title4<ul> <li>url1</li> <li>url2</li> </ul></li> </ul>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.