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 6344459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:38:29+00:00 2026-05-24T20:38:29+00:00

I have a situation that I can not wrap my head around at the

  • 0

I have a situation that I can not wrap my head around at the moment. Multiple Time Overlaps. I’ve seen many posts on two times that overlap but nothing that has multiple times overlapping.

Here’s the data I would like to place in:

<?php
//RUN EACH Class Selection for Monday
foreach($class as $Classes){
    $time[] = array($ClassStartTime, $ClassEndTime, $classID);
}

OverLapFunction($time);
?>

Which would then post the classID and Overlapping Amount. Has anyone run into this situation before? Or figured out how to do this?

  • 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-24T20:38:30+00:00Added an answer on May 24, 2026 at 8:38 pm

    Say your data is like this:

    $classes = array(
        array(
           'name' => 'A',
           'day'  => 'Monday',
           'start'=> '08:00AM',
           'end'  => '11:00AM',
        ),
        array(
           'name' => 'B',
           'day'  => 'Monday',
           'start'=> '10:00AM',
           'end'  => '11:30AM',
        ),
        array(
           'name' => 'C',
           'day'  => 'Monday',
           'start'=> '12:00PM',
           'end'  => '04:00PM',
        ),
        array(
           'name' => 'D',
           'day'  => 'Monday',
           'start'=> '03:00PM',
           'end'  => '06:00PM',
        ),
    );
    

    You just need a nested foreach, like this:

    $overlap = array();
    foreach ($classes as $class1) {
        foreach ($classes as $class2) {
            if ($class1['day'] != $class2['day'] || $class1 == $class2) continue;
            if (strtotime($class1['start']) <  strtotime($class2['end']) &&
                strtotime($class1['start']) >= strtotime($class2['start']))
            {
                $array = array($class1['name'], $class2['name']);
                sort($array);
                if (!in_array($array, $overlap)) $overlap[] = $array;
            }
        }
    }
    

    Basically, it compares each class to all classes. If $class1 start time is less than $class2 end time and $class1 start time is more than $class2 start time: they overlap. Keep in mind that each class will be compared to each other twice (e.g.: A to B, B to A), so if it doesn’t match on the first pass, it will in the second.

    This’ll give you:

    Array
    (
        [0] => Array
            (
                [0] => B
                [1] => A
            )
    
        [1] => Array
            (
                [0] => D
                [1] => C
            )
    
    )
    

    If you were to change class D to:

    array(
       'name' => 'D',
       'day'  => 'Monday',
       'start'=> '10:00AM',
       'end'  => '03:00PM',
    ),
    

    …effectively overlapping all classes, you’d get:

    Array
    (
        [0] => Array
            (
                [0] => A
                [1] => B
            )
    
        [1] => Array
            (
                [0] => B
                [1] => D
            )
    
        [2] => Array
            (
                [0] => C
                [1] => D
            )
    
        [3] => Array
            (
                [0] => A
                [1] => D
            )
    
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a situation like this http://jsfiddle.net/9cRpe/ . You can see that the &#09
Apparently I have a unique situation that I can't find help with anywhere. I'm
I have weird situation in newly installed server, and it seems that Google can't
I hit some behaviour I can't seem to wrap my head around. Say I
Currently in our enterprise we have a situation that i think it's not very
I have a situation that I can't seem to resolve. It is causing a
I have a situation that I solved in the following way: //cube_potentials is float8
I have a situation that requires redirecting users who are already logged in away
I have that situation: I have models Item, Region and Country. class Item(models.Model): name
I have an interesting situation that EMF forced me into: abstract class AbstractDog{ ...

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.