0

Is there any way for me to have a foreach statement like:

foreach($item in $array1){
    //code goes here
}
3
  • 1
    Yes, but the arguments are the other way around, and you use as instead of in: foreach ($array1 as $item) {...}. Commented Jan 18, 2014 at 20:45
  • 1
    Is foreach ($array1 as $item) { /* code goes here */ } close enough? Commented Jan 18, 2014 at 20:45
  • I'm trying to make an array called blanks, and I'd like to use less code. The foreach statement would add a _ to the array for each letter in the secret word. I'm making hangman Commented Jan 18, 2014 at 20:46

1 Answer 1

6

Yes:

foreach ($array1 as $item) {
    // code goes here
}

Reference: PHP foreach()

Sign up to request clarification or add additional context in comments.

Comments

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.