Re: Find Resource Overlaps in an Array

From: Date: Thu, 08 Jul 2021 18:01:50 +0000
Subject: Re: Find Resource Overlaps in an Array
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-327580@lists.php.net to get a copy of this message
I think I figured out the first function: function check_for_overlap($array, $resource, $sourceStart, $sourceEnd, $KeyResource, $tKeyStart, $tKeyEnd){ $out = array(); if(is_array($array)){ foreach ($array as $r){ if ($r[$KeyResource] == $resource){ if($sourceStart < $r[$tKeyEnd] && $sourceEnd > $r[$tKeyStart]){ $out[] = $r; } } } } if(count($out) > 0) return true; } I would appreciate if someone one would confirm that this will work or if there is a more efficient way to handle this. Thanks! No to move to the next function. Don > On Jul 8, 2021, at 8:45 AM, Don Wieland <donw@pointmade.net> wrote: > > $lessons = Array > ( > [0] => Array > ( > [res] => 45 > [start] => 2021-07-14 16:00:00 > [end] => 2021-07-14 16:45:00 > [start_int] => 1626292800 > [end_int] => 1626295500 > [tdur_slot] => 18 > ) > > [1] => Array > ( > [res] => 45 > [start] => 2021-07-14 16:45:00 > [end] => 2021-07-14 17:30:00 > [start_int] => 1626295500 > [end_int] => 1626298200 > [tdur_slot] => 18 > ) > > [2] => Array > ( > [res] => 45 > [start] => 2021-07-14 17:30:00 > [end] => 2021-07-14 18:30:00 > [start_int] => 1626298200 > [end_int] => 1626301800 > [tdur_slot] => 24 > ) > > [3] => Array > ( > [res] => 9 > [start] => 2021-07-14 10:00:00 > [end] => 2021-07-14 10:45:00 > [start_int] => 1626271200 > [end_int] => 1626273900 > [tdur_slot] => 18 > ) > > ) > > I am trying to compile two functions to help with scheduling lessons (conflicts and checking > for valid availability). > > function check_for_overlap($array, $resource, $sourceStart, $sourceEnd, $KeyResource, > $tKeyStart, $tKeyEnd){

« previous php.general (#327580) next »