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

  • SEARCH
  • Home
  • 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 5981957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:01:04+00:00 2026-05-22T22:01:04+00:00

Hi guys i need to convert a foreach loop into a while loop. Because

  • 0

Hi guys i need to convert a foreach loop into a while loop.
Because the foreach loop does leaves the block when values have been iterated. I need the while loop to continue looping.

I need to iterate the items of the array but not in a foreach loop.

foreach($values as $event) {
        if($startDate >= $event['start'] && $startDate <= $event['end']  ) {
            echo '<tr><td style="background:red;">Tijd: ' . strftime("== %H:%M ==", $startDate) . '<br/></td><td>'.$startDate.'</td></tr>';
        }
        else {
            echo '<tr><td style="background:green;">Tijd: ' . strftime("== %H:%M ==", $startDate) . '<br/></td><td>'.$startDate.'</td></tr>';
        }       
    }

My last post when into a disaster srry for that.

  • 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-05-22T22:01:06+00:00Added an answer on May 22, 2026 at 10:01 pm

    If you simply want to iterate through the array, this should do it:

    $array_length = count($values);
    $iteration    = 0;
    
    while($iteration < $array_length){
        $event = $values[$iteration];
        ...
        $iteration++;
    }
    

    This functionality is much like a for() or foreach() loop, if you only want to exit the loop when a specific condition is met, you could do it like this:

    $active = true;
    $iteration = 0;
    
    while($active){
        $event = $values[$iteration];
        ...
        if(some_condition){ $active = false; }
        $iteration++;
    }
    

    Note: You should put in some code which resets the iterator or sets $active to false if the iterator grows larger than or equal to the size of the values array, or else you will run into trouble

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

Sidebar

Related Questions

Hay guys, i need help with a REGEX. I have the got the value
I have found this amazing control that does exactly what I need, only problem,
Hey guys I need to know who to put these array objects into two
i have distance in a variable of type CLLocationDistance i need to convert it
I have some .class files that I need to convert to .java so I
I have pdf with fillable fields. How can I guys convert it automatically to
Ok guys, need to turn off the cookies in my ASP.net site completely I'm
Do you guys came across any sample application (i need source code of the
I really need help with interfaces in general... Any resources that you guys would
Guys, I’ve been writing code for 15+ years, but managed to avoid Web Development

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.