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 trialninyo
15,367 Pointscombining variables to create another variable?
Say I wanted this write this php line amongst others
$output = $output . $count_xd . "xd";
I also have an array with values ('xd','fed','id')
is there a way that from within a loop i can output
$output = $output . $count_xd . "xd";
$output = $output . $count_fed . "fed";
$output = $output . $count_id . "id";
without having to write each one? so like
$output = $output . $count_'.$b.' . "'.$b.'";
I know it's wrong, but I hope you get the idea. Thanks guys!
2 Answers
Mark Truitt
17,230 PointsNot really, however the choice of wording makes it difficult to understand.
I'm taking a guess what your attempting to do is to concatenate the data in one variable into another?
If so, then you would just run the array through a foreach loop.
I would recommend doing the https://teamtreehouse.com/library/php-basics the PHP conditionals & loops section to get a better idea on how you can do just what your asking.
ninyo
15,367 PointsWow. Thanks.
All I was asking is how to dynamically create variables through looping. If you don't know then don't answer. Lol. I'll give you a point for that last sentence.
ninyo
15,367 Pointsthe third php snippet should have given you an idea Mark Truitt
Mark Truitt
17,230 PointsMark Truitt
17,230 PointsNot sure what you mean by "combining" variables to create another variable.