How to get the total hour from starting time to end time in php



PHP Snippet 1:

$t1 = strtotime('2013-08-07 23:00:00');
$t2 = strtotime('2013-08-08 01:00:00');
$differenceInSeconds = $t2 - $t1;
$differenceInHours = $differenceInSeconds / 3600;

PHP Snippet 2:

    for ($i = 0; $i < count($array); $i++) { //array contains your sorted times like [H:i]
        $a = $array[$i]. " " .date("Y/m/d");
        $array[$i] = $a;
    }
    
    $total=0;
    for ($i = count($array); $i>1; $i--){
        if ($array[$i-1] < $array[$i-2]){
            $array[$i-1] = strtotime("+1 day", strtotime($array[$i-1]));
            $z = "a";
        }
        $a = strtotime($array[$i-1]);
        $b = strtotime($array[$i-2]);
        $diff = $a - $b;    
        $hours = ceil($diff / (24*60));
        $total += date("H", $hours);
    }
if ($z == "a"){
    $total += date("H", ceil(strtotime($array[0]) / (24*60)));
}