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 Build a Simple PHP Application Integrating with PayPal Forms, Arrays, and Get Variables

Imon Dela Rosa
Imon Dela Rosa
7,383 Points

[SOLVED] Hi! I think there is a bug in this quiz.

$flavors = array();

$flavors[1] = "Cake Batter";

$flavors[2] = "Cookie Dough";

if (isset($_GET["id"])) {

    if (isset($flavors[$_GET["id"]])) {

        echo $flavors[$_GET["id"]];

    } else {

        echo "B";

    }

} else {

    echo "A";

}

I answered: A But, I was incorrect by the system

2 Answers

Hey Imon Dela Rosa,

It depends on what was set with the "flavor.php" page in the question area. I've done that question multiple ways just a few moments ago to see if there is a bug, and I can find none. I've seen it 4 different ways. One has the id not set at all; one has the id set to a number (9 for me) that is undefined on the array; one has it set to the id of 1; and one has it set to the id of 2. It's impossible to say which question you got based upon that 2nd part you copied. Again, each time I took the quiz and got the different question, I was able to find the correct answer.

I also edited your markdown so it would render correctly on the screen. You can check out the Markdown Cheatsheet for how to post code (which has a link just below every comment or answer input area).

Imon Dela Rosa
Imon Dela Rosa
7,383 Points

Hi! Marcus, you were right. I overlooked the url with id. http://localhost/flavor.php?id=1 Means the answer is D. Cake Batter.

Thank you.

Excellent, Imon! I'm glad you've solved your dilemma. I'll go ahead and mark this as solved. :)