3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $period_start = '2016-01-01 00:00:00'; $period_end = '2016-01-31 23:59:59'; $uptime = []; $incidents = [ ['start' => '2016-01-05 00:00:00', 'end' => '2016-01-10 23:59:59'], ['start' => '2016-01-07 00:00:00', 'end' => '2016-01-15 23:59:59'], ['start' => '2016-01-20 00:00:00', 'end' => '2016-01-25 23:59:59'], ['start' => '2016-01-23 00:00:00', 'end' => '2016-01-24 23:59:59'] ]; if(strtotime($period_start) <= strtotime($incidents[0]['start'])) { array_push($uptime,['start' => $period_start, 'end' => $incidents[0]['start']]); } for($i=0;$i<sizeof($incidents);$i++) { if($incident[$i+1]) { if(strtotime($incident[$i]['end']) > strtotime($incident[$i+1]['start'])) { echo "sap"; } } } if(strtotime($period_end) >= strtotime($incidents[sizeof($incidents)-1]['end'])) { array_push($uptime,['start' => $incidents[0]['end'], 'end' => $period_end]); } print_r( $uptime );
based on AKmT2
Output for 5.6.0 - 7.3.0beta1
Notice: Undefined variable: incident in /in/XkoJW on line 20 Notice: Undefined variable: incident in /in/XkoJW on line 20 Notice: Undefined variable: incident in /in/XkoJW on line 20 Notice: Undefined variable: incident in /in/XkoJW on line 20 Array ( [0] => Array ( [start] => 2016-01-01 00:00:00 [end] => 2016-01-05 00:00:00 ) [1] => Array ( [start] => 2016-01-10 23:59:59 [end] => 2016-01-31 23:59:59 ) )