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

Cliff Jackson
Cliff Jackson
2,887 Points

Can someone explain clearly what is happening here, why is the output A?

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

}

?>

1 Answer

The "id" variable wasn't set therefore the conditional wasn't met.

At least I think that's what it is.

Cliff Jackson
Cliff Jackson
2,887 Points

Thanks i figured it in the end.