Link to home
Start Free TrialLog in
Avatar of saabStory
saabStoryFlag for United States of America

asked on

Need help with understanding and fixing a multidimensional array

I'm creating a dynamic equivalent of a javascript menu.  I've got the top tabs worked out but was wanting to put the sub menus into a multidimensional array.  I've got it so long as it's static but as soon as I plug it into the loop, it either gives back the word 'array' or gives me an error about not using a string offset as an array - and I"m having trouble figuring out why that is the case.

There are only two elements I'm pulling back - the name of the tab, which is obviously a string and the recordID which will be an integer.  The code below is part my code and part example I found on the web.  Since the example worked, I started reverse-engineering it to add my database code.  Everything worked statically - but that only gave me information on the very last tab.  To build the whole thing, I need to put it in a loop, build an array of the arrays and then take that and build out the sub-navigation.  Once I put the working static code into the array, that's when I got the message about using a string offset.

Many thanks in advance for all your help.
//PHP LOOP FOR BUILDING INITIAL ARRAY
while(odbc_fetch_row($result)) {								
$tempArray = array("".odbc_result($result,'TabName')."","".odbc_result($result,'TabID')."", 15);
$shop .= array($tempArray);
}

//OUTPUT TEST FOR MULTIDIMENSIONAL ARRAY
echo "Tab Name: ".$shop[0][0]." Tab ID: ".$shop[0][1]." -- Ignore ".$shop[0][2]."<br />";
echo "Tab Name: ".$shop[1][0]." Tab ID: ".$shop[1][1]." -- Ignore ".$shop[1][2]."<br />";
echo "Tab Name: ".$shop[2][0]." Tab ID: ".$shop[2][1]." -- Ignore ".$shop[2][2]."<br />";

Open in new window

Avatar of StingRaY
StingRaY
Flag of Thailand image

To push something into an array, use [] instead of .

//PHP LOOP FOR BUILDING INITIAL ARRAY
while(odbc_fetch_row($result)) {                                                                
$tempArray = array("".odbc_result($result,'TabName')."","".odbc_result($result,'TabID')."", 15);
$shop[] = array($tempArray);
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of StingRaY
StingRaY
Flag of Thailand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of saabStory

ASKER

Excellent - many thanks.  The ultimate goal of all this is create a universal nav for all our sites where all I have to feed in is the database name and table name and a function builds the nav on the fly.  I'm almost there thanks to this.