AdRock Posted December 19, 2013 Share Posted December 19, 2013 I have an array like but larger and it could have different types and levels. This array is taken from MySQL and I've called it $courses array(23) { [0]=> array( { ["name"]=> string(43) "Conservation of Decorative Arts" ["type"]=> string(12) "conservation" ["url"]=> NULL ["level"]=> string(1) "1" } [1]=> array( { ["name"]=> string(32) "Diploma in Restoration" ["type"]=> string(12) "conservation" ["url"]=> NULL ["level"]=> string(1) "1" } [2]=> array( { ["name"]=> string(20) "Diploma in Finishing" ["type"]=> string(12) "craft" ["url"]=> NULL ["level"]=> string(1) "1" } What I want to do is output the array so i can echo out the Name and URL and order it by Type so i get something like <h1>Conservation</h1> <ul> <li><a href=""></a></li> <li><a href=""></a></li> <li><a href=""></a></li> </ul> <h1>Craft</h1> <ul> <li><a href=""></a></li> <li><a href=""></a></li> <li><a href=""></a></li> </ul> I 've tried using nested foreach() loops but it prints the same value out multiple times so instead of about 15 rows, i end up with about 100 with loads of duplicate rows one after the other // $this->courses is the MySQL array <?php foreach($this->courses as $course): ?> <?php foreach($course as $key => $value): ?> <li><?=$course['name'];?></li> <?php endforeach; ?> <?php endforeach; ?> What am i doing wrong? Link to comment https://forums.phpfreaks.com/topic/284846-outputting-multidimensional-array/ Share on other sites More sharing options...
AdRock Posted December 19, 2013 Author Share Posted December 19, 2013 Just turned out to be a simple foreach not a nested foreach. Just a simple solution and I was blinded by the obvious Link to comment https://forums.phpfreaks.com/topic/284846-outputting-multidimensional-array/#findComment-1462724 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.