Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9175489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:55:21+00:00 2026-06-17T16:55:21+00:00

is it possible to have 2 conditions in the same foreach loop with one

  • 0

is it possible to have 2 conditions in the same foreach loop with one which continues, and one which breaks. so I want to find all full input fields and make them $$key, but make only the first empty input field $_POST['email']. can I do this in the same loop or do I nee 2 loops?
here is an example, this doesn’t work, it breaks.

foreach( $_POST as $key=> $for ) {
    if ( $for!='') {
        $$key = $for;   continue;
    } else if ( $for=='') { 
        $$key = $_POST['email'];  break;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:55:22+00:00Added an answer on June 17, 2026 at 4:55 pm

    Your example code doesn’t make a lot of sense: if ($for!=''), then the only other thing which can possibly be is $for=='', therefore the second if clause is redundant. Further, what are you tring to achive by setting the result in $$key – there may be a reason for this but it is not shown in the code you’ve published.

    Yes, it’s quite possible to have multiple break and continue constructs inside a loop. And they will work properly.

    However it would be much more efficient to implement your code as simply:

    $email=$_POST['email'];
    

    (although this also removes a lot side-effects and potential vulnerabilities from the code).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible for Java foreach to have conditions? For example, for(Foo foo :
I have a long query like this: $a=$this->Signin->find('all', array( 'fields'=> array( ..... ), 'conditions'
Is it possible have two projects with the same name in flex builder? Here
I have an array a=[1,2,3,4,5,6,7,8,9] and I want to find the indices of the
I have a query where not all conditions are necessary. Here's an example of
I have a very simple query (three where conditions; two equals, one between) from
Is it possible to have assignment in a condition? For ex. if (a=some_func()): #
Possible Duplicate: php false place in condition I have noticed that a lot of
Is it possible for me to have a conditional in XSLT such that I
is possible to have a separator between elements of a GridView? Thanks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.