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


Working with Functions: Multiple Choice Quiz

What does the following code display?


$x = 1;

function sum_two_numbers($x,$y) {

$z = $x + $y;

return $z; 


$y = sum_two_numbers(2,3);

echo $x; 


Can someone explain to me how to find the value of $x? I greatly appreciate it.

3 Answers

$x=1; // This is the first occurance of the variable x being assigned a value of 1. $x is not modified again. The statement echo $x; simply displays the variable x's value which is still the value of 1. I hope this helps...

The function sum_two_numbers uses the $x variable but limited scope. It means that the $x variable inside the function and outside the function are essentially different variables.


Thanks for the clarification about $x variable with limited scope. This makes sense now. Thank you!

No problem. It kind of messed with me too.