3v4l.org

run code in 300+ PHP versions simultaneously
<?php // suppose this is your mysql data, each inner pair is a 'to', 'from' $rows = array( array(1,6), array(7,10), array(8,12) ); list($a, $b) = current($rows); $downtime = $b - $a; while( list($c, $d) = next($rows) ) { $downtime += $d - $c - max(0, min($d,$b)-$c); if( $c >= $b ) $a = $c; $b = max($b,$d); } echo "total down time is " , $downtime; ?>

preferences:
27.71 ms | 407 KiB | 5 Q