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

Justin LeFurjah
Justin LeFurjah
12,347 Points

Is this PHP question right?

From forms, arrays and get variables quiz:

I visit my flavor.php file with an extra variable in the web address, like this: http://localhost/flavor.php <--(what is the extra variable)

If my flavor.php file has the code shown below, what does it output?

<?php

$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";

}

?>

3 Answers

Marileen Mennerich
Marileen Mennerich
1,161 Points

The question is correct like this. As you mention yourself, the extra variable is not set, thus if (isset($_GET["id"])) -> false. The output should be A, in that case.

Justin LeFurjah
Justin LeFurjah
12,347 Points

My question wasn't about the answer, it was about the question :) Thanks for your feedback in any case.

Marileen Mennerich
Marileen Mennerich
1,161 Points

Well, yes, the question is right. It may be oddly worded ("with an extra variable" --> there is none) but it still tests the user's understanding of the concept. Or is there anything else that seems off to you about this question?

Justin LeFurjah
Justin LeFurjah
12,347 Points

"I visit my flavor.php file with an extra variable in the web address, like this: http://localhost/flavor.php"

(i) the question says there is an extra variable in the web address. (ii) there is no extra variable in the web address.

I think we agree on these points. Where we seem to differ is in our interpretation of what follows from them.

At first I wasn't sure if I had missed something regarding the meaning of "extra variable" or if the question was wrong, or oddly worded as you say.

Marileen Mennerich
Marileen Mennerich
1,161 Points

Yes, interpretation seems to be the issue. i did this course just recently and do not remember stumbling over this wording (as in: it was clear to me what the intended answer was) but I definitely see how it could throw people off or make them unsure about the answer. Simply leaving out the "with an extra variable" part would suffice I guess. Maybe a staff member will look into this and agree.