只有当两个日期超过4秒时才计算它们之间的间隔

I'm facing a little problem, and i need your help :)

I explain : I have an array of 2 dates like this :

DateMin : 16/03/2016 19:12:08   DateMax : 16/03/2016 19:18:29
DateMin : 16/03/2016 19:12:08   DateMax : 16/03/2016 19:18:30
DateMin : 16/03/2016 19:12:09   DateMax : 16/03/2016 19:18:30
DateMin : 16/03/2016 19:12:09   DateMax : 16/03/2016 19:18:31
DateMin : 07/04/2016 12:14:21   DateMax : 07/04/2016 12:31:03

What i would like to do is to count the interval beetween 2 dates, only if this interval is more than 4seconds.

Here is what i'm trying to do :

foreach($res as $r){
            if(isset($output[$r['DATE']])) {
                $dateBefore = null;
                $dateSql = DateTime::createFromFormat("d/m/Y G:i:s",$r['DATE']);
                if($dateBefore == null){
                    $dateBefore = DateTime::createFromFormat("d/m/Y G:i:s",$r['DATE']);
                }
                $interval = $dateSql->diff($dateBefore);
                if($interval->format('%s') > 4){
                    $dateBefore = DateTime::createFromFormat("d/m/Y G:i:s",$r['DATE']);
                    $output[$r['DATE']] += intval($interval->format('%s'));
                }
            }
            else
                $output[$r['DATE']] = 0;
        }

I guess, you need to change

if($interval->format('%s') > 4)

as

if($interval->format('%R%a') > 4)

and

$output[$r['DATE']] += intval($interval->format('%s'));

as

$output[$r['DATE']] += intval($interval->format('%R%a'));