Okay, basically, I'm trying to build a navigation tree out of several different arrays. One array holds information about each category, such as name, a second name to reference, and the array which holds the links for each section:

$navcategories = array (
     // Categories
          'general' => array ('General', 'general', $navgeneral),
          'reviews' => array ('Reviews', 'reviews', $navreviews),
          'animemanga' => array ('Anime/Manga', 'animemanga', $navanime),
          'gaming' => array ('Gaming', 'gaming', $navgaming),
          'misc' => array ('Miscellaneous', 'misc', $navmisc)
);

So, basically it references another array. However, I'm having trouble calling the second array. I'm trying to do it like so:

              foreach ($navcategories as $cat) {

                  print ('
                                                         <li class="navcat"><div class="navcat">' . $cat[0] . '</div></li>
                  ');

                  foreach ($cat[2] as $link) {

                          print ('
                                                                     <li class="navlink"><div class="navblock"></div><div class="navlink"><a href="index.php?tare=' . $link[0] . '" class="nav">' . key($link) . '</a></div></li>
                          ');

                  };

                  print ('
                                                         <br />
                  ');

          };

The error I'm getting is:

Warning: Invalid argument supplied for foreach() in /home/ketsuka/public_html/frozensky/Themes/v1/Template.Index.php on line 48

Line 48 is:

foreach ($cat[2] as $link) {

    does this help

    $nav = array (
    // Categories
    'general' => array ('General', 'general', $navgeneral),
    'reviews' => array ('Reviews', 'reviews', $navreviews),
    'animemanga' => array ('Anime/Manga', 'animemanga', $navanime),
    'gaming' => array ('Gaming', 'gaming', $navgaming),
    'misc' => array ('Miscellaneous', 'misc', $navmisc)
    );

    foreach ($nav as $item)
    {
    echo($item[0])."<BR>";

    foreach($item as $cat)
    {
    	?>
    	<div class="navlink"><a href="index.php?tare=<?php echo $cat; ?>" class="nav">-- <?php echo $cat; ?></a></div><BR />
    	<?
    }

    }

      Umm ... not really. It's pretty much what I was doing before, except not calling the item. Let me try this again. Structure:

      Array 1: $categories = array (Name, second name, $arraywithlinks)

      Arrays 2-6: $arraywithlinks = array ('linkpath' => array ('Name', 'treelinks')

      That reference of $arraywithlinks in Array 1 is what I need to call, but I need to call it as one of the other arrays. Basically, I need to figure out how to reference the items in $arraywithlinks via $categories[2]. Or some other way of connecting the different arrays without combining them...

        So I came up with something like this.... not sure if it's what you want or if it helps:

        <?php
        $navgeneral = array(
        	'domain.com/' => array('Home', 'index.html'),
        );
        
        $navreviews = array(
        	'domain.com/reviews/' => array('First Ever', 'review1.html'),
        );
        
        $navanime = array(
        	'domain.com/anime/' => array('For Kids', 'kids.html'),
        );
        
        $navgaming = array(
        	'domain.com/gaming/' => array('xBox', 'xbox.html'),
        );
        
        $navmisc = array(
        	'domain.com/misc/' => array('Other Junk', 'junk.html'),
        );
        
        $navcategories = array(
        	'general' => array('General', 'general', $navgeneral),
        	'reviews' => array('Reviews', 'reviews', $navreviews),
        	'animemanga' => array('Anime/Manga', 'animemanga', $navanime),
        	'gaming' => array('Gaming', 'gaming', $navgaming),
        	'misc' => array('Miscellaneous', 'misc', $navmisc)
        );
        
        // Loop through categories showing all subsequent links:
        echo '<ul>';
        foreach($navcategories AS $cat)
        {
        	echo '
        	<li style="min-height: 15px;"><div>', $cat[0], '</div>
        		<ul>';
        
        foreach($cat[2] AS $sub)
        {
        	echo '
        		<li style="min-height: 15px;"><div><a href="', key($cat[2]), $sub[1], '">', $sub[0], '</a></div></li>';
        }
        
        echo '
        	</ul>
        </li>';
        }
        echo '
        </ul>';
        
        ?>

        You never specified too well your array setup, so I can't be sure that's what will work for your case. But it's something for you to work off of.

        Almost forgot the output:

            *
              General
                  o
                    Home
            *
              Reviews
                  o
                    First Ever
            *
              Anime/Manga
                  o
                    For Kids
            *
              Gaming
                  o
                    xBox
            *
              Miscellaneous
                  o
                    Other Junk

          Sorry. That probably would have helped had I actually shown you the link arrays. Anyway, thanks for the help, though I don't know if it would have worked. I figured out there were two problems.

          The first was that when I referenced the link arrays in the category arrays, they hadn't been declared yet. I moved the category array around in the file and fixed that one.

          The second problem was that in the second foreach statement, the ($cat[2] as $link/$sub) one, it was apparently putting out to a variable instead of an array, so the key() function wouldn't take it. Well, I got rid of the foreach statement altogether and went with this:

                                while ($link = each ($cat[2])) {
          
                                  print ('
                                                                             <li class="navlink"><div class="navblock"></div><div class="navlink"><a href="index.php?tare=' . $link['key'] . '" class="nav">' . $link['value'] . '</a></div></li>
                                  ');
          
                            };

          But, like I said, thanks for your help anyway.

            Write a Reply...