SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $json='[{"from":"2019-07-22 09:00:00","to":"2019-07-22 11:00:00","rendering":"background","resource":"3529","backgroundColor":"#660000","purpose":"Close"},{"from":"2019-07-22 07:00:00","to":"2019-07-22 08:00:00","rendering":"background","resource":"3529","backgroundColor":"#660000","purpose":"Close"},{"from":"2019-07-22 07:00:00","to":"2019-07-22 08:00:00","rendering":"background","resource":"3529","backgroundColor":"#660000","purpose":"Open"},{"from":"2019-07-22 20:00:00","to":"2019-07-22 22:00:00","rendering":"background","resource":"3529","backgroundColor":"#660000","purpose":"Open"},{"from":"2019-07-22 10:00:00","to":"2019-07-22 17:00:00","rendering":"background","resource":"3529","backgroundColor":"#660000","purpose":"Open"},{"from":"2019-07-22 20:00:00","to":"2019-07-22 22:00:00","rendering":"background","resource":"3529","backgroundColor":"#660000","purpose":"Close"},{"from":"2019-07-22 07:00:00","to":"2019-07-22 15:00:00","rendering":"background","resource":"3529","backgroundColor":"#660000","purpose":"Close"}]';
  2.      
  3. Array
  4. (
  5.     [0] => Array
  6.         (
  7.             [from] => 2019-07-22 09:00:00
  8.             [to] => 2019-07-22 11:00:00
  9.             [rendering] => background
  10.             [resource] => 3529
  11.             [backgroundColor] => #660000
  12.             [purpose] => Close
  13.         )
  14.  
  15.     [1] => Array
  16.         (
  17.             [from] => 2019-07-22 07:00:00
  18.             [to] => 2019-07-22 08:00:00
  19.             [rendering] => background
  20.             [resource] => 3529
  21.             [backgroundColor] => #660000
  22.             [purpose] => Close
  23.         )
  24.  
  25.     [2] => Array
  26.         (
  27.             [from] => 2019-07-22 07:00:00
  28.             [to] => 2019-07-22 08:00:00
  29.             [rendering] => background
  30.             [resource] => 3529
  31.             [backgroundColor] => #660000
  32.             [purpose] => Open
  33.         )
  34.  
  35.     [3] => Array
  36.         (
  37.             [from] => 2019-07-22 20:00:00
  38.             [to] => 2019-07-22 22:00:00
  39.             [rendering] => background
  40.             [resource] => 3529
  41.             [backgroundColor] => #660000
  42.             [purpose] => Open
  43.         )
  44.  
  45.     [4] => Array
  46.         (
  47.             [from] => 2019-07-22 10:00:00
  48.             [to] => 2019-07-22 17:00:00
  49.             [rendering] => background
  50.             [resource] => 3529
  51.             [backgroundColor] => #660000
  52.             [purpose] => Open
  53.         )
  54.  
  55.     [5] => Array
  56.         (
  57.             [from] => 2019-07-22 20:00:00
  58.             [to] => 2019-07-22 22:00:00
  59.             [rendering] => background
  60.             [resource] => 3529
  61.             [backgroundColor] => #660000
  62.             [purpose] => Close
  63.         )
  64.  
  65.     [6] => Array
  66.         (
  67.             [from] => 2019-07-22 07:00:00
  68.             [to] => 2019-07-22 15:00:00
  69.             [rendering] => background
  70.             [resource] => 3529
  71.             [backgroundColor] => #660000
  72.             [purpose] => Close
  73.         )
  74.  
  75. )
  76.      
  77. Array
  78. (
  79.     [0] => Array
  80.         (
  81.             [from] => 2019-07-22 09:00:00
  82.             [to] => 2019-07-22 11:00:00
  83.             [rendering] => background
  84.             [resource] => 3529
  85.             [backgroundColor] => #660000
  86.             [purpose] => Close
  87.         )
  88.     [1] => Array
  89.         (
  90.             [from] => 2019-07-22 07:00:00
  91.             [to] => 2019-07-22 08:00:00
  92.             [rendering] => background
  93.             [resource] => 3529
  94.             [backgroundColor] => #660000
  95.             [purpose] => Close
  96.         )
  97.     [2] => Array
  98.         (
  99.             [from] => 2019-07-22 20:00:00
  100.             [to] => 2019-07-22 22:00:00
  101.             [rendering] => background
  102.             [resource] => 3529
  103.             [backgroundColor] => #660000
  104.             [purpose] => Open
  105.         )
  106.     [3] => Array
  107.         (
  108.             [from] => 2019-07-22 11:00:00
  109.             [to] => 2019-07-22 17:00:00
  110.             [rendering] => background
  111.             [resource] => 3529
  112.             [backgroundColor] => #660000
  113.             [purpose] => Open
  114.         )
  115. )
  116.      
  117. $newSlotselse=array();
  118.  
  119.                             foreach($thisthearray as $closekey=>$closeval){
  120.                                 if(empty($newSlotselse)){
  121.                                     $newSlotselse[]=$closeval;
  122.                                 }else{
  123.                                     $curfrom=$closeval['from'];
  124.                                     $curto=$closeval['to'];
  125.                                     foreach($newSlotselse as $exceptionkey=>$exceptionval){
  126.                                         //some static vars
  127.                                         $consider=true;
  128.                                         $case=0;
  129.                                         if($curfrom==$exceptionval['from'] && $curto==$exceptionval['to']){
  130.                                             //case 1
  131.                                             $consider=false;
  132.                                             $case=1;
  133.                                             break;
  134.                                         }else if($curfrom < $exceptionval['to'] && $curto > $exceptionval['to']){
  135.                                             //case 2
  136.                                             $curfrom=$exceptionval['to'];
  137.                                             $case=2;
  138.                                             break;
  139.                                         }else if(($curfrom < $exceptionval['from'] && $curto < $exceptionval['to']) && ($curto > $exceptionval['from'])){
  140.                                             //case 3
  141.                                             $curto=$exceptionval['from'];
  142.                                             $case=3;
  143.                                             break;
  144.                                         }else if($curfrom > $exceptionval['from'] && $curto < $exceptionval['to']){
  145.                                             //case 4
  146.                                             $curfrom=$exceptionval['to'];
  147.                                             $case=4;
  148.                                             break;
  149.                                         }else if($curfrom < $exceptionval['from'] && $curto > $exceptionval['to']){
  150.                                             //case 5
  151.                                             $consider=false;
  152.                                             $case=5;
  153.                                             break;
  154.                                         }else if($curfrom > $exceptionval['from'] && $curto > $exceptionval['to']){
  155.                                             //case 6
  156.                                             $consider=true;
  157.                                             $case=6;
  158.                                             break;
  159.                                         }else if($curfrom < $exceptionval['from'] && $curto < $exceptionval['to']){
  160.                                             //case 7
  161.                                             $consider=true;
  162.                                             $case=7;
  163.                                             break;
  164.                                         }
  165.                                     }
  166.  
  167.  
  168.                                     if($consider){
  169.                                         $newSlotselse[]=array('from'=>$curfrom, 'to'=>$curto, 'rendering'=>$closeval['rendering'], 'resource'=>$closedval['resource'], 'backgroundColor'=>$closedval['backgroundColor'], 'purpose'=>$closeval['purpose'], 'case'=>$case, 'iteration'=>$closekey);
  170.                                     }
  171.                                 }
  172.                             }
  173.      
  174. <pre>Array
  175. (
  176.     [0] => Array
  177.         (
  178.             [from] => 2019-07-22 09:00:00
  179.             [to] => 2019-07-22 11:00:00
  180.             [rendering] => background
  181.             [resource] => 3529
  182.             [backgroundColor] => #660000
  183.             [purpose] => closedexception
  184.         )
  185.  
  186.     [1] => Array
  187.         (
  188.             [from] => 2019-07-22 07:00:00
  189.             [to] => 2019-07-22 08:00:00
  190.             [rendering] => background
  191.             [resource] => 3529
  192.             [backgroundColor] => #660000
  193.             [purpose] => closedexception
  194.         )
  195.  
  196.     [2] => Array
  197.         (
  198.             [from] => 2019-07-22 07:00:00
  199.             [to] => 2019-07-22 08:00:00
  200.             [rendering] => background
  201.             [resource] => 3529
  202.             [backgroundColor] => #660000
  203.             [purpose] => closedexception
  204.         )
  205.  
  206.     [3] => Array
  207.         (
  208.             [from] => 2019-07-22 20:00:00
  209.             [to] => 2019-07-22 22:00:00
  210.             [rendering] => background
  211.             [resource] => 3529
  212.             [backgroundColor] => #660000
  213.             [purpose] => closedexception
  214.         )
  215.  
  216.     [4] => Array
  217.         (
  218.             [from] => 2019-07-22 10:00:00
  219.             [to] => 2019-07-22 17:00:00
  220.             [rendering] => background
  221.             [resource] => 3529
  222.             [backgroundColor] => #660000
  223.             [purpose] => closedexception
  224.         )
  225.  
  226.     [5] => Array
  227.         (
  228.             [from] => 2019-07-22 20:00:00
  229.             [to] => 2019-07-22 22:00:00
  230.             [rendering] => background
  231.             [resource] => 3529
  232.             [backgroundColor] => #660000
  233.             [purpose] => closedexception
  234.         )
  235.  
  236.     [6] => Array
  237.         (
  238.             [from] => 2019-07-22 07:00:00
  239.             [to] => 2019-07-22 15:00:00
  240.             [rendering] => background
  241.             [resource] => 3529
  242.             [backgroundColor] => #660000
  243.             [purpose] => closedexception
  244.         )
  245.  
  246. )
  247.      
  248. $json='[{"from":"2019-07-22 09:00:00","to":"2019-07-22 11:00:00","rendering":"background","resource":"3529","backgroundColor":"#660000","purpose":"Close"},{"from":"2019-07-22 07:00:00","to":"2019-07-22 08:00:00","rendering":"background","resource":"3529","backgroundColor":"#660000","purpose":"Close"},{"from":"2019-07-22 07:00:00","to":"2019-07-22 08:00:00","rendering":"background","resource":"3529","backgroundColor":"#660000","purpose":"Open"},{"from":"2019-07-22 20:00:00","to":"2019-07-22 22:00:00","rendering":"background","resource":"3529","backgroundColor":"#660000","purpose":"Open"},{"from":"2019-07-22 11:00:00","to":"2019-07-22 17:00:00","rendering":"background","resource":"3529","backgroundColor":"#660000","purpose":"Open"},{"from":"2019-07-22 20:00:00","to":"2019-07-22 22:00:00","rendering":"background","resource":"3529","backgroundColor":"#660000","purpose":"Close"},{"from":"2019-07-22 07:00:00","to":"2019-07-22 15:00:00","rendering":"background","resource":"3529","backgroundColor":"#660000","purpose":"Close"}]';
  249. //var_export(json_decode($json, true));
  250. foreach (json_decode($json, true) as $i => $entry) {
  251.     if (!$i) {
  252.         $result[] = $entry;
  253.     } else {
  254.         foreach ($result as $stored) {
  255.             if (($entry['from'] >= $stored['from'] && $entry['from'] < $stored['to'])
  256.                 || ($entry['to'] > $stored['from'] && $entry['to'] <= $stored['to'])) {
  257.                 continue 2;
  258.             }
  259.         }
  260.         $result[] = $entry;
  261.     }
  262. }
  263. var_export($result);
  264.      
  265. array (
  266.   0 =>
  267.   array (
  268.     'from' => '2019-07-22 09:00:00',
  269.     'to' => '2019-07-22 11:00:00',
  270.     'rendering' => 'background',
  271.     'resource' => '3529',
  272.     'backgroundColor' => '#660000',
  273.     'purpose' => 'Close',
  274.   ),
  275.   1 =>
  276.   array (
  277.     'from' => '2019-07-22 07:00:00',
  278.     'to' => '2019-07-22 08:00:00',
  279.     'rendering' => 'background',
  280.     'resource' => '3529',
  281.     'backgroundColor' => '#660000',
  282.     'purpose' => 'Close',
  283.   ),
  284.   2 =>
  285.   array (
  286.     'from' => '2019-07-22 20:00:00',
  287.     'to' => '2019-07-22 22:00:00',
  288.     'rendering' => 'background',
  289.     'resource' => '3529',
  290.     'backgroundColor' => '#660000',
  291.     'purpose' => 'Open',
  292.   ),
  293.   3 =>
  294.   array (
  295.     'from' => '2019-07-22 11:00:00',
  296.     'to' => '2019-07-22 17:00:00',
  297.     'rendering' => 'background',
  298.     'resource' => '3529',
  299.     'backgroundColor' => '#660000',
  300.     'purpose' => 'Open',
  301.   ),
  302. )
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top