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 trial
Derrick Lee
7,743 PointsHelp with getting values of an array inside an array in a function.
I am trying to recode my HTML portfolio website into PHP based on the PHP lessons so far from treehouse. Basically, it retrieves all my portfolio item from an array and lists them out.
Here is how my code looks like
portfolio.php
** The function which will be called **
** The array which contains the project types **
** The array which contains the portfolio items **
My problem is that, I am using a filterable portfolio gallery and I need to load the project element into the function as a class in this html tag '<div class="six columns element">'
Simply put, I am trying to retrieve the values of the array in the $projects["projectType"] and put them into '<div class="six columns element ' . PUT HERE . '">'
The problem is that, there can be more than one project type, it can be just "web", or sometimes it can be "web graphic", the more project type it has, the bigger the project and it will stay throughout the filters.
4 Answers
Derrick Lee
7,743 PointsSolved the problem by putting a foreach loop outside the $output = $output, just below the $output = ""
foreach ($project["projectType"] as $projectType) {
$theType = $projectType . " " . $theType;
}
Followed by displaying $theType to the element
Ryan Carson
23,287 PointsGood job Derrick! :)
Derrick Lee
7,743 PointsThank you Ryan! I spent a day figuring this out, only to solve it after I posted the question.
Jonathan Davies
2,162 PointsI would love to know how he did this, i am also struggling to learn how to do it.



