Need help with understanding and fixing a multidimensional array

saabStory
saabStory used Ask the Experts™
on
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

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
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

Commented:
And I'd be better if you assign an empty array to $shop before entering the loop

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

Open in new window

Author

Commented:
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.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial