Search the Community
Showing results for tags 'multi dimensional array'.
-
I am creating a dynamic human readable sitemap from mysql>php. the array is created with; (array structure can be altered if this is causing the grief) <?php $row['category'] = varchar; // list of 10 categories $row['status'] = int; // 0,1 or 2 $row['id'] = int; // 1,2,3,4... (AI) // set the title for link $this->sitemap[$row['category']][$row['status']]['title'][$row['id']] = $row['seo_title']; // set the url for link $this->sitemap[$row['category']][$row['status']]['url'][$row['id']] = $row['slug'].".php"; ?> My required output to be as; <ul> <li>category[0] <ul> // all category[0][2] <li><a href="category[0][2]['title']['the row id']">category[0][2]['title']['the row id']</a></li> etc... // all category[0][1] <ul> <li><a href="category[0][1]['title']['the row id']">category[0][1]['title']['the row id']</a></li> etc.... // all category[0][0] <ul> <li><a href="category[0][0]['title']['the row id']">category[0][0]['title']['the row id']</a></li> </ul> </ul> <li>category[1] <ul> // all category[1][2] <li><a href="category[1][2]['title']['the row id']">category[1][2]['title']['the row id']</a></li> etc... keep in mind where caetgory[0] is a string as key, not an integer. Any ideas or questions welcomed, thanks.
-
Hi, I decided to learn PHP & MySQL from scratch with "PHP & MySQL in Easy Steps" by Mike McGrath. Page 35 is a tutorial on Describing Dimensions. I think I've done exactly what it says, but my output is weird. The php code I wrote: <?php $letters = array('A','B','C','D','E','F','G'); $numbers = array(1,2,3,4,5,6); $matrix = array('Letters'=> $letters,'Number'=> $numbers); echo "<p>Start: {$matrix['Letter'][0]}</p>"; foreach($matrix as $array => $list) { echo '<ul>'; foreach($list as $key => $value) {echo "<li>$array[$key]=$value";} echo '</ul>'; } ?> According to the book should display like this: Start: A - Letter [0] = A - Letter [1] = B - Letter [2] = C - Number[0] = 1 - Number[1] = 2 - Number[2] = 3 I've checked my code twice. And had a friend check it. Can't find a difference between the book and my code, yet mine appears like this: Start: L=A e=B t=C t=D e=E r=F s=G N=1 u=2 m=3 b=4 e=5 r=6 What's wrong with it!?