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


Ivan Burda
Ivan Burda
10,897 Points

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

You 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
Ivan Burda
10,897 Points

Thank you, Jonathan! Now I finally understand it. Have a nice evening.