Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pag sum lahat ng oras HH:MM:SS
- at pag convert ng HH:MM:SS to seconds
- <?php
- $times = array();
- $times[] = "01:00:00";
- $times[] = "01:30:60";
- // pass the array to the function
- echo AddPlayTime($times);
- function AddPlayTime($times) {
- $minutes = 0; //declare minutes either it gives Notice: Undefined variable
- $seconds = 0;
- // loop throught all the times
- foreach ($times as $time) {
- list($hour, $minute, $seconds1) = explode(':', $time);
- $minutes += $hour * 60;
- $minutes += $minute;
- $seconds += $seconds1;
- // echo $seconds.' ';
- }
- $hours = floor($minutes / 60);
- $minutes -= $hours * 60;
- // returns the time already formatted
- return sprintf('%02d:%02d:%02d', $hours, $minutes,$seconds);
- }
- $str_time = AddPlayTime($times);
- $str_time = preg_replace("/^([\d]{1,2})\:([\d]{2})$/", "00:$1:$2", $str_time);
- sscanf($str_time, "%d:%d:%d", $hours, $minutes, $seconds);
- $time_seconds = $hours * 3600 + $minutes * 60 + $seconds;
- echo "</br>";
- echo $time_seconds;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement