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 trialammarkhan
Front End Web Development Techdegree Student 21,661 PointsWhere does the shirts gets it id?
I see the page display each id of the shirt when clicked, but where does price/product_id comes from? and why are we using => in the loop?
2 Answers
Nicklas Wiborg
12,692 Pointsthe => in the loop creates a variable with the key of the item in the array.
if you have:
$array = new array("first","second");
You have a array with the following:
$array[0] = "first";
$array[1] = "second";
If we loop trough this array with the foreach-loop, like this:
foreach($array as $item_key => $item){
}
$item_key will be assigned the key of the array-item which is in this case 0 for "first" and 1 for "second".
ammarkhan
Front End Web Development Techdegree Student 21,661 Pointsyou mean like if we have a array like '''html $product = array(); $product['101'] => apple; ''' so when we do foreach loop, with $key => $value , the $key will become 101?
p.s - How do you format boxes for code?
Joakim Nordlund
5,610 PointsIt's in the Markdown Cheatsheet right below here.
Wrap your code with 3 backticks (```) on the line before and after. If you specify the language after the first set of backticks, that'll help us with syntax highlighting.
```html
<p>This is code!</p>
```
Nicklas Wiborg
12,692 PointsYes! If you have a properly functioning array it will.
Nicklas Wiborg
12,692 PointsNicklas Wiborg
12,692 PointsIf I extend my answer:
Will return "01";