0
$array = Array(1,2,3);
foreach ($array as $identifier => $values_arr);
{
     echo(123);
}

The result is 123 instead of 123123123.

2 Answers 2

4

What you have are actually two different segments of code.

The first:

foreach ($array as $identifier => $values_arr);

doesn't actually do anything, and is stopped.

And the second:

{echo (123);}

so the output is 123

to get into the foreach you will need to remove the semi-colon:

foreach ($array as $identifier => $values_arr){
     echo(123);
}
Sign up to request clarification or add additional context in comments.

Comments

-1

There is an extra colon on the end of the foreach line. The same issue often happens with if/else lines. I am posting this as I could not find the answer via Google search.

1 Comment

The same issue often happens with if/else lines. No it doesn't; being able to construct valid code blocks is pretty trivial.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.