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

PHP

Is there a way to dynamically create new variables through looping?

I'm trying to understand how to create this

Imagine having an array with three values:

$array = array('one','two','three');

I'd like to find a way to output these using a foreach loop

foreach(){

$variable_one $variable_two $variable_three

}

How do i set up the code to create $variable_[dynamic]? Sorry for my lack terminology.

1 Answer

Something like this should work:

var $array = ['one','two','three']; var $arrayLength = $array.length; for (var i = 0; i < arrayLength; i++) { var $array[i]; }

Nice thanks for the response, Is this PHP?

Also, how can I go about researching the documentation for this? As in how can I reword this question on google so It would pull up what I'm looking for?

Thank you Jon Schiedermayer