Given an array containing the time in hr:min:sec format. The task is to calculate the total time. If the total time is greater then 24 hours then the total time will not start with 0. It will display the total time. There are two ways to calculate the total time from the array.
- Using strtotime() function
- Using explode() function
Using strtotime() function: The strtotime() function is used to convert string into the time format. This functions returns the time in h:m:s format.
strtotime( string )
Example 1: This example reads the values from the array and converts it into the time format.
Using explode() function: The explode() function is used to break a string into an array.
array explode( separator, string, limit )
Example 2: This example reads the values from an array and converts it into the time format.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.