Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialRafal Bachanek
28,766 Pointsusing loops with arrays
I have array:
$restaurants = array ( "happy_hour => array ( "happy_hour1" => array (
describe => "something" ), "happy_hour2" => array (
describe => "something" )
) );
i would like to echo all describe data for every restaurant which loop. Could anyone have idea how to do that?
1 Answer
Ted Sumner
Courses Plus Student 17,967 PointsIf I understand your code example correctly, you have an array continaing arrays and you want to display the content of the inner arrays. There are several ways to do this, but I think nested foreach loops would be a way to display the contents.
<?php
foreach ($parentArray as $parent) {
foreach ($parent as $child) {
echo $child; //your real code here.
}
}