7
$arr = array(1,2,3,4,5);

foreach($arr as $key => $row) {
    echo current($arr);
}

//output is 22222, why?

Why the result is not 12345?

3
  • 2
    Have you read the docs for current ? You're effectively asking about the internals of foreach (in what way and when it advances the pointer - or not). Commented Jun 24, 2014 at 8:36
  • maybe because we're all confused here Commented Jun 24, 2014 at 8:38
  • @AD7six Then I would delete that comment Commented Jun 24, 2014 at 8:38

1 Answer 1

0

if you want the output to be 12345:

$arr = array(1,2,3,4,5);

foreach($arr as $key => $val) {
    echo $val;
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.