What will be the output value of the following code?
$array = array(1,2,3);
while (list(,$v) = each($array));
var_dump(current($array));
Suggested Answer: A
Get Premium 200-710 Questions
as Interactive Web-Based Practice Test or PDF
Real Exam Format
Detailed Explanations
Instant Access
Get Your Practice Test
43 comments · newest first
BE
Beatriz
11 months ago
Agreed, the while loop exhausts the array.
MI
Miriam
12 months ago
Wait, how can it be NULL? That seems off.
ZI
Zita
12 months ago
Definitely int(3).
FR
Franklyn
1 year ago
I think it should be bool(false).
TA
Tanja
1 year ago
The output will be NULL.
BA
Bambi
1 year ago
I thought `current()` would return the last value, which is `3`, but now I'm confused about how the loop affects it.
TI
Timothy
1 year ago
I feel like the output might be `NULL` since the loop goes through all elements, but I can't recall if `current()` resets the pointer.
AS
Ashley
1 year ago
I remember a similar question where we used `current()` after a loop, and it returned `false` when the array was exhausted.
GO
Goldie
1 year ago
I think the `each()` function will iterate through the array, but I'm not sure what happens to the current pointer after that.
NE
Nelida
1 year ago
Okay, I think I've got it - the while loop will iterate through the array, but the var_dump() will only show the final value. I'll go with B.
MO
Mollie
1 year ago
I'm a bit confused by the use of current() after the while loop. I'll need to think this through more carefully.
AL
Alexia
1 year ago
The while loop with list() seems tricky, I'll need to carefully step through the code to figure out the output.
JE
Jerilyn
1 year ago
I think I know how to solve this, but I want to double-check my understanding before answering.
SE
Selma
1 year ago
Ah, I remember learning about the each() function in PHP. I believe the output will be the last element in the array, so I'll go with B.
LO
Lorrie
1 year ago
I've seen similar questions before. I think I know the right approach, but I'll double-check my work to be sure.
EL
Elmira
2 years ago
Haha, this question is a real brain-teaser! I'm going to go with option B, int(3), because that's the only answer that seems somewhat logical.
JO
Johana
2 years ago
I agree with option B, int(3)
SH
Sherman
2 years ago
I'm going with bool(false)
MI
Mireya
2 years ago
I believe it will be NULL
KR
Kristel
2 years ago
I think the output will be int(1)
HA
Harris
2 years ago
Wait, what? This question is as clear as mud. I'll just go with option E, Array, because that's the only answer that makes sense to me.
CO
Corrie
2 years ago
I agree with you, I'll choose Array
TO
Toshia
2 years ago
I'm going with bool(false)
LE
Leontine
2 years ago
I believe it will be NULL
VI
Viva
2 years ago
I think the output will be int(1)
KE
Kendra
2 years ago
I think the output will be int(3) because the current function returns the current element in an array.
CL
Claudio
2 years ago
I'm not sure, but I think it might be bool(false).
LE
Leigha
2 years ago
I'm not sure about this one. The code looks a bit weird, but I'm going to go with option D, NULL, just to be safe.
LA
Lauran
2 years ago
I agree, let's go with option D.
LE
Lenna
2 years ago
I think it will be option D, NULL.
MA
Margo
2 years ago
I believe the output will be NULL.
MA
Marva
2 years ago
I think the output will be int(1).
JU
Juan
2 years ago
No way, the output is clearly int(3)! The while loop just iterates through the array, and current() will return the last element.
MA
Mammie
2 years ago
No, it's actually bool(false).
RO
Rose
2 years ago
I think the output is int(3).
NA
Nan
2 years ago
Hmm, I think the output will be bool(false), since the while loop has already exhausted the array and current() will return the last element's value.
CH
Christa
2 years ago
I agree with you, it should be bool(false).
DE
Devora
2 years ago
I'm pretty sure it will be int(3).
QU
Quentin
2 years ago
I believe it will be NULL.
SH
Shenika
2 years ago
I think the output will be int(1).
BR
Brett
2 years ago
I agree with you, the output should be bool(false) as current() will return false after the while loop.
AL
Aliza
2 years ago
I believe it will be NULL because the array has been exhausted by the while loop.
DA
Dawne
2 years ago
I think it will be int(1) because current() will return the first element's value.