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!
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

Ivan Burda
10,897 PointsPHP - Paypal Quiz - $flavors as $a => $b
Hi. I am going through the PHP track and integrating PayPal with the web. However, there is something, I do not understand. Can somebody explain to me how this works, please?
Especially, I do not understand the idea behind $flavors as $a => $b
This code is also included in the quiz and the correct answers is that its outcome would be "01". Why?
Thank you.
$flavors = array("Cake Batter","Cookie Dough");
foreach ($flavors as $a => $b) {
echo $a;
1 Answer

Jonathan Petersen
45,721 PointsYou are outputting the key of the key-value pair. $a is the key $b is the value. Keys start at 0.
foreach($array as $key => $value){}
So at position 0 the value is "Cake Batter" at position 1 the value is "Cookie Dough"
Did that answer your question or is your confusion coming from the loop?
Ivan Burda
10,897 PointsIvan Burda
10,897 PointsThank you, Jonathan! Now I finally understand it. Have a nice evening.