I understand that by calculate he meant addition.
(Nuances related to translation). Below is an example function in Laravel that adds these times from an array. You should use Carbon for this purpose.
Note: the resulting $time variable is a Carbon date from unix time = 0 with the times added from your array.
The sum of seconds from your array can thus be retrieved using the timestamp property, which is the amount of seconds since the start of the unix epoch:
3
Answers
I understand that by calculate he meant addition.
(Nuances related to translation). Below is an example function in Laravel that adds these times from an array. You should use Carbon for this purpose.
I believe you want sum the durations of time. We can transform it in a collection and reduce it by adding the times.
Summing times can be done using Carbon like so (less is more):
Note: the resulting
$time
variable is a Carbon date from unix time = 0 with the times added from your array.The sum of seconds from your array can thus be retrieved using the
timestamp
property, which is the amount of seconds since the start of the unix epoch:Displaying it as a string goes as follows: