0

i got this array

$total = array('1:00','2:20','4:00','5:10');

i try to SUM the total time with this

$sum = strtotime('00:00:00');
foreach ($total as $v){
   $sum = $sum+strtotime($v);
}
echo date("H:i:s",$sum);

but the result is 19:40:40 should be 12:30

haidarvm
  • 611
  • 8
  • 17
  • more possible duplicates in http://stackoverflow.com/search?q=how+to+sum+time+[php] - please use the search function before asking. – Gordon Mar 03 '14 at 06:38
  • that's completly different question please see mine , i have multi value array ,the question you gave only for two value and it's not in array – haidarvm Mar 03 '14 at 08:25

1 Answers1

1

Try This code:

You need to add only the array timimgs then add to todays timings:

$total = array('1:00','2:20','4:00','5:10');

 $sum = strtotime('00:00:00');
 $sum2=0;  
 foreach ($total as $v){

        $sum1=strtotime($v)-$sum;

        $sum2 = $sum2+$sum1;
    }

    $sum3=$sum+$sum2;

    echo date("H:i:s",$sum3);
Vikas Umrao
  • 2,800
  • 1
  • 15
  • 23