Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

Zend Exam 200-710 Topic 8 Question 50 Discussion

Actual exam question for Zend's 200-710 exam
Question #: 50
Topic #: 8
[All 200-710 Questions]

What is the output of the following code?

function increment ($val)

{

++$val;

}

$val = 1;

increment ($val);

echo $val;

Show Suggested Answer Hide Answer
Suggested Answer: B

Contribute your Thoughts:

Sabina
2 months ago
Oh, I see. So the function is like a black box that just does its thing and doesn't give me back the new value. Time to brush up on my PHP function basics!
upvoted 0 times
Stefan
5 days ago
Jani: Exactly, it's important to remember how functions work in PHP.
upvoted 0 times
...
Meaghan
6 days ago
User 3: So the original value of $val remains unchanged.
upvoted 0 times
...
Jani
7 days ago
User 2: Yeah, the function just increments the value but doesn't return it.
upvoted 0 times
...
Daren
2 months ago
User 1: The output is 1.
upvoted 0 times
...
...
Tommy
2 months ago
I got this one! The output is 1 because the increment() function only modifies the local copy of $val, not the original variable. The echo statement outside the function still prints the original value of 1.
upvoted 0 times
...
Judy
2 months ago
Haha, this is a classic gotcha question! I remember seeing something similar in my last exam. The key is that the function doesn't return the incremented value, it just modifies the original variable. So the output will be 1.
upvoted 0 times
Joanna
1 months ago
I got tricked by that as well. It's 1.
upvoted 0 times
...
Simona
1 months ago
Definitely a common mistake to make.
upvoted 0 times
...
Joanna
1 months ago
Yeah, I fell for that one too. The output is 1.
upvoted 0 times
...
Britt
2 months ago
I always forget about passing by reference in PHP.
upvoted 0 times
...
Simona
2 months ago
Yeah, I fell for that one too. It's tricky!
upvoted 0 times
...
...
Ashley
3 months ago
Actually, the output is 1 because the increment function is not returning the updated value.
upvoted 0 times
...
Yesenia
3 months ago
I think the output is 2 because the increment function should increase the value by 1.
upvoted 0 times
...
Colby
3 months ago
Wait, why is the output not 1? Isn't the function just incrementing the value and then returning it? I'm confused.
upvoted 0 times
Raymon
25 days ago
That's why the output is still 1.
upvoted 0 times
...
Nana
26 days ago
So when you echo $val outside the function, it remains unchanged.
upvoted 0 times
...
Ruthann
27 days ago
The function is only changing the value locally within the function.
upvoted 0 times
...
Dusti
1 months ago
The function is incrementing the value, but it is not returning the updated value.
upvoted 0 times
...
Niesha
1 months ago
Got it, thanks for explaining!
upvoted 0 times
...
Shawna
1 months ago
Exactly, that's why the output is still 1.
upvoted 0 times
...
Dorothy
2 months ago
Oh, so the value of $val is not being changed outside of the function.
upvoted 0 times
...
Twana
2 months ago
The function is incrementing the value, but it's not returning the updated value.
upvoted 0 times
...
...
Ashley
3 months ago
The output is 1.
upvoted 0 times
...
Linette
3 months ago
Actually, the output is 1 because the function is not returning the incremented value.
upvoted 0 times
...
Georgeanna
3 months ago
The output will be 2. The increment operator (++) increments the value of $val by 1, so after calling the increment() function, the value of $val should be 2.
upvoted 0 times
Weldon
2 months ago
Yes, it will be 2.
upvoted 0 times
...
Rachael
2 months ago
No, it will be 1.
upvoted 0 times
...
Mary
2 months ago
The output will be 2.
upvoted 0 times
...
Dylan
3 months ago
The output will be 1.
upvoted 0 times
...
...
Lura
3 months ago
I think the output will be 2 because the function is incrementing the value.
upvoted 0 times
...
Linette
4 months ago
The output is 1.
upvoted 0 times
...

Save Cancel